#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;
return TRUE;
}
+static GPtrArray *buffer_cache = NULL;
+
static void
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))
if (frame_tvb->buf) {
ws_buffer_free(frame_tvb->buf);
-
- g_free(frame_tvb->buf);
+ g_ptr_array_add(buffer_cache, frame_tvb->buf);
}
}
}
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