Reduce malloc pressure in stringcache (thanks, Max!).
authorRyan C. Gordon <icculus@icculus.org>
Mon, 23 Jun 2014 14:56:00 -0400
changeset 1141 77468a2a9165
parent 1140 fad7ed946c06
child 1142 7b554e065321
Reduce malloc pressure in stringcache (thanks, Max!).
mojoshader_common.c
--- a/mojoshader_common.c	Mon Jun 23 14:50:56 2014 -0400
+++ b/mojoshader_common.c	Mon Jun 23 14:56:00 2014 -0400
@@ -366,15 +366,10 @@
         return NULL;
 
     // add to the table.
-    bucket = (StringBucket *) cache->m(sizeof (StringBucket), cache->d);
+    bucket = (StringBucket *) cache->m(sizeof (StringBucket) + len + 1, cache->d);
     if (bucket == NULL)
         return NULL;
-    bucket->string = (char *) cache->m(len + 1, cache->d);
-    if (bucket->string == NULL)
-    {
-        cache->f(bucket, cache->d);
-        return NULL;
-    } // if
+    bucket->string = (char *)(bucket + 1);
     memcpy(bucket->string, str, len);
     bucket->string[len] = '\0';
     bucket->next = cache->hashtable[hash];
@@ -462,7 +457,6 @@
         while (bucket)
         {
             StringBucket *next = bucket->next;
-            f(bucket->string, d);
             f(bucket, d);
             bucket = next;
         } // while