Effectively remove the tree memory pool and port some of its behaviour to the
authorEvan Huus <eapache@gmail.com>
Mon, 4 Nov 2013 14:12:59 +0000 (14:12 -0000)
committerEvan Huus <eapache@gmail.com>
Mon, 4 Nov 2013 14:12:59 +0000 (14:12 -0000)
pinfo memory pool, they have exactly the same scope. Simplification and minor
performance win (one GHashTable we longer have to create/destroy on every
packet).

svn path=/trunk/; revision=53076

epan/epan.c
epan/proto.c
epan/proto.h

index 7dfe3a71e92623531e74f6cccbe6697ffa1757f4..21b38e2682e55a446332303d6115170b62b5b4aa 100644 (file)
@@ -67,6 +67,8 @@
 #include <ares_version.h>
 #endif
 
+static wmem_allocator_t *pinfo_pool_cache = NULL;
+
 const gchar*
 epan_get_version(void) {
        return VERSION;
@@ -224,6 +226,15 @@ epan_dissect_init(epan_dissect_t *edt, epan_t *session, const gboolean create_pr
 
        edt->session = session;
 
+       memset(&edt->pi, 0, sizeof(edt->pi));
+       if (pinfo_pool_cache != NULL) {
+               edt->pi.pool = pinfo_pool_cache;
+               pinfo_pool_cache = NULL;
+       }
+       else {
+               edt->pi.pool = wmem_allocator_new(WMEM_ALLOCATOR_BLOCK);
+       }
+
        if (create_proto_tree) {
                edt->tree = proto_tree_create_root(&edt->pi);
                proto_tree_set_visible(edt->tree, proto_tree_visible);
@@ -234,9 +245,6 @@ epan_dissect_init(epan_dissect_t *edt, epan_t *session, const gboolean create_pr
 
        edt->tvb = NULL;
 
-       memset(&edt->pi, 0, sizeof(edt->pi));
-       edt->pi.pool = wmem_allocator_new(WMEM_ALLOCATOR_SIMPLE);
-
        return edt;
 }
 
@@ -334,7 +342,13 @@ epan_dissect_cleanup(epan_dissect_t* edt)
                proto_tree_free(edt->tree);
        }
 
-       wmem_destroy_allocator(edt->pi.pool);
+       if (pinfo_pool_cache == NULL) {
+               wmem_free_all(edt->pi.pool);
+               pinfo_pool_cache = edt->pi.pool;
+       }
+       else {
+               wmem_destroy_allocator(edt->pi.pool);
+       }
 }
 
 void
index cd8788fbc76a8040f3ff573b75f83b9483b6b05b..8bef0f6bae50a314ab6f3a8fb0271e14706260ea 100644 (file)
@@ -252,8 +252,6 @@ struct _protocol {
 /* List of all protocols */
 static GList *protocols = NULL;
 
-static wmem_allocator_t *tree_pool_cache = NULL;
-
 /* Contains information about a field when a dissector calls
  * proto_tree_add_item.  */
 #define FIELD_INFO_NEW(pool, fi)  fi = wmem_new(pool, field_info)
@@ -573,8 +571,6 @@ proto_tree_reset(proto_tree *tree)
        /* Reset track of the number of children */
        tree_data->count = 0;
 
-       wmem_free_all(tree_data->mem_pool);
-
        PROTO_NODE_INIT(tree);
 }
 
@@ -582,7 +578,6 @@ proto_tree_reset(proto_tree *tree)
 void
 proto_tree_free(proto_tree *tree)
 {
-       wmem_allocator_t *pool = PNODE_POOL(tree);
        tree_data_t *tree_data = PTREE_DATA(tree);
 
        proto_tree_children_foreach(tree, proto_tree_free_node, NULL);
@@ -597,15 +592,6 @@ proto_tree_free(proto_tree *tree)
                g_hash_table_destroy(tree_data->interesting_hfids);
        }
 
-       if (tree_pool_cache) {
-               /* if we already have one cached then just destroy it */
-               wmem_destroy_allocator(pool);
-       }
-       else {
-               wmem_free_all(pool);
-               tree_pool_cache = pool;
-       }
-
        g_slice_free(tree_data_t, tree_data);
 
        g_slice_free(proto_tree, tree);
@@ -4090,17 +4076,8 @@ proto_item_get_len(const proto_item *pi)
 proto_tree *
 proto_tree_create_root(packet_info *pinfo)
 {
-       wmem_allocator_t *pool;
        proto_node *pnode;
 
-       if (tree_pool_cache) {
-               pool = tree_pool_cache;
-               tree_pool_cache = NULL;
-       }
-       else {
-               pool = wmem_allocator_new(WMEM_ALLOCATOR_BLOCK);
-       }
-
        /* Initialize the proto_node */
        pnode = g_slice_new(proto_tree);
        PROTO_NODE_INIT(pnode);
@@ -4111,8 +4088,6 @@ proto_tree_create_root(packet_info *pinfo)
        /* Make sure we can access pinfo everywhere */
        pnode->tree_data->pinfo = pinfo;
 
-       pnode->tree_data->mem_pool = pool;
-
        /* Don't initialize the tree_data_t. Wait until we know we need it */
        pnode->tree_data->interesting_hfids = NULL;
 
index 273d74a7645d4a9fa1033773b2b401a86f9f30ee..e0b54fb83e3920fb3eb76d758b994739101f4bba 100644 (file)
@@ -486,7 +486,6 @@ typedef struct {
     gboolean     fake_protocols;
     gint         count;
     struct _packet_info *pinfo;
-    wmem_allocator_t    *mem_pool;
 } tree_data_t;
 
 /** Each proto_tree, proto_item is one of these. */
@@ -611,7 +610,7 @@ WS_DLL_PUBLIC void proto_tree_children_foreach(proto_tree *tree,
 #define PTREE_DATA(proto_tree)   ((proto_tree)->tree_data)
 
 /** Retrieve the wmem_allocator_t from a proto_node */
-#define PNODE_POOL(proto_node)   ((proto_node)->tree_data->mem_pool)
+#define PNODE_POOL(proto_node)   ((proto_node)->tree_data->pinfo->pool)
 
 /** Sets up memory used by proto routines. Called at program startup */
 void proto_init(void (register_all_protocols_func)(register_cb cb, gpointer client_data),