Skip to content
Permalink
Browse files
Reduce malloc pressure in stringcache (thanks, Max!).
  • Loading branch information
icculus committed Jun 23, 2014
1 parent 4bdadc2 commit d1421a716b90a2f1cd61e3305a62a922a9ba85b8
Showing with 2 additions and 8 deletions.
  1. +2 −8 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

0 comments on commit d1421a7

Please sign in to comment.