[Diameter] Add a couple of command codes from IANA.
[metze/wireshark/wip.git] / frame_tvbuff.c
index cc027222836117a8111673bbf068e3d01dbcca4e..9af5d2ff4d0a6d91207c9ac38ce852d32d98d08b 100644 (file)
@@ -31,7 +31,7 @@
 #include "frame_tvbuff.h"
 #include "globals.h"
 
-#include "wtap-int.h" /* for ->random_fh */
+#include "wiretap/wtap-int.h" /* for ->random_fh */
 
 struct tvb_frame {
        struct tvbuff tvb;
@@ -69,6 +69,8 @@ frame_read(struct tvb_frame *frame_tvb, struct wtap_pkthdr *phdr, Buffer *buf)
        return TRUE;
 }
 
+static GPtrArray *buffer_cache = NULL;
+
 static void
 frame_cache(struct tvb_frame *frame_tvb)
 {
@@ -77,9 +79,14 @@ frame_cache(struct tvb_frame *frame_tvb)
        wtap_phdr_init(&phdr);
 
        if (frame_tvb->buf == NULL) {
-               frame_tvb->buf = (struct Buffer *) g_malloc(sizeof(struct Buffer));
+               if G_UNLIKELY(!buffer_cache) buffer_cache = g_ptr_array_sized_new(1024);
+
+               if (buffer_cache->len > 0) {
+                       frame_tvb->buf = (struct Buffer *) g_ptr_array_remove_index(buffer_cache, buffer_cache->len - 1);
+               } else {
+                       frame_tvb->buf = (struct Buffer *) g_malloc(sizeof(struct Buffer));
+               }
 
-               /* XXX, register frame_tvb to some list which frees from time to time not used buffers :] */
                ws_buffer_init(frame_tvb->buf, frame_tvb->tvb.length + frame_tvb->offset);
 
                if (!frame_read(frame_tvb, &phdr, frame_tvb->buf))
@@ -98,8 +105,7 @@ frame_free(tvbuff_t *tvb)
 
        if (frame_tvb->buf) {
                ws_buffer_free(frame_tvb->buf);
-
-               g_free(frame_tvb->buf);
+               g_ptr_array_add(buffer_cache, frame_tvb->buf);
        }
 }
 
@@ -139,13 +145,13 @@ frame_find_guint8(tvbuff_t *tvb, guint abs_offset, guint limit, guint8 needle)
 }
 
 static gint
-frame_pbrk_guint8(tvbuff_t *tvb, guint abs_offset, guint limit, const guint8 *needles, guchar *found_needle)
+frame_pbrk_guint8(tvbuff_t *tvb, guint abs_offset, guint limit, const ws_mempbrk_pattern* pattern, guchar *found_needle)
 {
        struct tvb_frame *frame_tvb = (struct tvb_frame *) tvb;
 
        frame_cache(frame_tvb);
 
-       return tvb_pbrk_guint8(tvb, abs_offset, limit, needles, found_needle);
+       return tvb_ws_mempbrk_pattern_guint8(tvb, abs_offset, limit, pattern, found_needle);
 }
 
 static guint