]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - util.c
Track strdups too in the statistics
[xonotic/gmqcc.git] / util.c
diff --git a/util.c b/util.c
index cc825690cc4e78136fd40d8a6dde03de82978972..351aba6d8bb4732357a779a1765280237d82fd33 100644 (file)
--- a/util.c
+++ b/util.c
@@ -208,6 +208,7 @@ void util_st_put(size_table_t table, size_t key, size_t value) {
     table[hash]->value = value;
 }
 
+static uint64_t      strdups      = 0;
 static uint64_t      vectors      = 0;
 static uint64_t      vector_sizes = 0;
 static size_table_t  vector_usage = NULL;
@@ -249,26 +250,30 @@ void util_meminfo() {
     
     if (OPTS_OPTION_BOOL(OPTION_STATISTICS) ||
         OPTS_OPTION_BOOL(OPTION_MEMCHK)) {
-        size_t i;
+        size_t i=0;
+        size_t e=1;
         
         con_out("Additional Statistics:\n\
-            Total vectors used:         %u\n\
+            Total vectors allocated:    %u\n\
+            Total string duplicates:    %u\n\
             Total unique vector sizes:  %u\n",
             (unsigned)vectors,
+            (unsigned)strdups,
             (unsigned)vector_sizes
         );
         
-        /* TODO: */
-        for (i = 0; i < ST_SIZE; i++) {
+        for (; i < ST_SIZE; i++) {
             size_entry_t *entry;
             
             if (!(entry = vector_usage[i]))
                 continue;
             
-            con_out("               # of %3u (bytes) vectors: %u\n",
+            con_out("               %u| # of %3u (bytes) vectors: %u\n",
+                (unsigned)e,
                 (unsigned)entry->key,
                 (unsigned)entry->value
             );
+            e++;
         }
     }
     
@@ -295,6 +300,7 @@ char *_util_Estrdup(const char *s, const char *file, size_t line) {
         memcpy(ptr, s, len);
         ptr[len] = '\0';
     }
+    strdups++;
     return ptr;
 }
 
@@ -314,6 +320,7 @@ char *_util_Estrdup_empty(const char *s, const char *file, size_t line) {
         memcpy(ptr, s, len);
         ptr[len] = '\0';
     }
+    strdups++;
     return ptr;
 }
 
@@ -732,28 +739,6 @@ void util_htrem(hash_table_t *ht, void (*callback)(void *data)) {
     mem_d(ht);
 }
 
-void util_htremkey(hash_table_t *ht, void (*callback)(void *data, const char *key)) {
-    size_t i = 0;
-    for (; i < ht->size; i++) {
-        hash_node_t *n = ht->table[i];
-        hash_node_t *p;
-
-        /* free in list */
-        while (n) {
-            if (callback)
-                callback(n->value, n->key);
-            mem_d(n->key);
-            p = n;
-            n = n->next;
-            mem_d(p);
-        }
-
-    }
-    /* free table */
-    mem_d(ht->table);
-    mem_d(ht);
-}
-
 void util_htrmh(hash_table_t *ht, const char *key, size_t bin, void (*cb)(void*)) {
     hash_node_t **pair = &ht->table[bin];
     hash_node_t *tmp;