From d1421a716b90a2f1cd61e3305a62a922a9ba85b8 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Mon, 23 Jun 2014 14:56:00 -0400 Subject: [PATCH] Reduce malloc pressure in stringcache (thanks, Max!). --- mojoshader_common.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/mojoshader_common.c b/mojoshader_common.c index 1edeb3fd..365619d4 100644 --- a/mojoshader_common.c +++ b/mojoshader_common.c @@ -366,15 +366,10 @@ static const char *stringcache_len_internal(StringCache *cache, 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 @@ void stringcache_destroy(StringCache *cache) while (bucket) { StringBucket *next = bucket->next; - f(bucket->string, d); f(bucket, d); bucket = next; } // while