]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
Some cleanups
authorDale Weiler <killfieldengine@gmail.com>
Sun, 2 Jun 2013 08:37:22 +0000 (08:37 +0000)
committerDale Weiler <killfieldengine@gmail.com>
Sun, 2 Jun 2013 08:37:22 +0000 (08:37 +0000)
gmqcc.h
stat.c

diff --git a/gmqcc.h b/gmqcc.h
index 8edcbda59de899e2da20d6ad98132fca7715b899..5922b840bb23394ad59b6140ade0db1821252d15 100644 (file)
--- a/gmqcc.h
+++ b/gmqcc.h
@@ -291,29 +291,12 @@ GMQCC_IND_STRING(GMQCC_VERSION_PATCH) \
 /*===================================================================*/
 /*=========================== stat.c ================================*/
 /*===================================================================*/
-typedef struct {
-    size_t key;
-    size_t value;
-} stat_size_entry_t, **stat_size_table_t;
-
 void  stat_info();
-
 char *stat_mem_strdup    (const char *, size_t,         const char *, bool);
 void *stat_mem_reallocate(void *,       size_t, size_t, const char *);
 void  stat_mem_deallocate(void *);
 void *stat_mem_allocate  (size_t, size_t, const char *);
 
-stat_size_table_t  stat_size_new();
-stat_size_entry_t *stat_size_get(stat_size_table_t, size_t);
-void               stat_size_del(stat_size_table_t);
-void               stat_size_put(stat_size_table_t, size_t, size_t);
-
-/* getters for hashtable: */
-stat_size_table_t *stat_size_hashtables_get();
-uint64_t          *stat_type_hashtables_get();
-uint64_t          *stat_used_hashtables_get();
-stat_size_table_t *stat_hashtables_init();
-
 #define mem_a(SIZE)              stat_mem_allocate  ((SIZE), __LINE__, __FILE__)
 #define mem_d(PTRN)              stat_mem_deallocate((void*)(PTRN))
 #define mem_r(PTRN, SIZE)        stat_mem_reallocate((void*)(PTRN), (SIZE), __LINE__, __FILE__)
diff --git a/stat.c b/stat.c
index 372cc143205ee5ce937fac666735fa715ac6adb2..7f8a498b80c2ce0d682173071d95f4935173891e 100644 (file)
--- a/stat.c
+++ b/stat.c
@@ -17,6 +17,11 @@ typedef struct stat_mem_block_s {
     struct stat_mem_block_s *prev;
 } stat_mem_block_t;
 
+typedef struct {
+    size_t key;
+    size_t value;
+} stat_size_entry_t, **stat_size_table_t;
+
 static uint64_t          stat_mem_allocated         = 0;
 static uint64_t          stat_mem_deallocated       = 0;
 static uint64_t          stat_mem_allocated_total   = 0;
@@ -32,6 +37,40 @@ static stat_size_table_t stat_size_vectors          = NULL;
 static stat_size_table_t stat_size_hashtables       = NULL;
 static stat_mem_block_t *stat_mem_block_root        = NULL;
 
+
+/*
+ * A tiny size_t key-value hashtbale for tracking vector and hashtable
+ * sizes. We can use it for other things too, if we need to. This is
+ * very TIGHT, and efficent in terms of space though.
+ */
+static stat_size_table_t stat_size_new() {
+    return (stat_size_table_t)memset(
+        mem_a(sizeof(stat_size_entry_t*) * ST_SIZE),
+        0, ST_SIZE * sizeof(stat_size_entry_t*)
+    );
+}
+
+static void stat_size_del(stat_size_table_t table) {
+    size_t i = 0;
+    for (; i < ST_SIZE; i++) if(table[i]) mem_d(table[i]);
+    mem_d(table);
+}
+
+static stat_size_entry_t *stat_size_get(stat_size_table_t table, size_t key) {
+    size_t hash = (key % ST_SIZE);
+    while (table[hash] && table[hash]->key != key)
+        hash = (hash + 1) % ST_SIZE;
+    return table[hash];
+}
+static void stat_size_put(stat_size_table_t table, size_t key, size_t value) {
+    size_t hash = (key % ST_SIZE);
+    while (table[hash] && table[hash]->key != key)
+        hash = (hash + 1) % ST_SIZE;
+    table[hash] = (stat_size_entry_t*)mem_a(sizeof(stat_size_entry_t));
+    table[hash]->key = key;
+    table[hash]->value = value;
+}
+
 /*
  * A basic header of information wrapper allocator. Simply stores
  * information as a header, returns the memory + 1 past it, can be
@@ -431,39 +470,6 @@ void util_htdel(hash_table_t *ht) {
     util_htrem(ht, NULL);
 }
 
-/*
- * A tiny size_t key-value hashtbale for tracking vector and hashtable
- * sizes. We can use it for other things too, if we need to. This is
- * very TIGHT, and efficent in terms of space though.
- */
-stat_size_table_t stat_size_new() {
-    return (stat_size_table_t)memset(
-        mem_a(sizeof(stat_size_entry_t*) * ST_SIZE),
-        0, ST_SIZE * sizeof(stat_size_entry_t*)
-    );
-}
-
-void stat_size_del(stat_size_table_t table) {
-    size_t i = 0;
-    for (; i < ST_SIZE; i++) if(table[i]) mem_d(table[i]);
-    mem_d(table);
-}
-
-stat_size_entry_t *stat_size_get(stat_size_table_t table, size_t key) {
-    size_t hash = (key % ST_SIZE);
-    while (table[hash] && table[hash]->key != key)
-        hash = (hash + 1) % ST_SIZE;
-    return table[hash];
-}
-void stat_size_put(stat_size_table_t table, size_t key, size_t value) {
-    size_t hash = (key % ST_SIZE);
-    while (table[hash] && table[hash]->key != key)
-        hash = (hash + 1) % ST_SIZE;
-    table[hash] = (stat_size_entry_t*)mem_a(sizeof(stat_size_entry_t));
-    table[hash]->key = key;
-    table[hash]->value = value;
-}
-
 /*
  * The following functions below implement printing / dumping of statistical
  * information.