Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Reduce malloc pressure in stringcache (thanks, Max!).
  • Loading branch information
icculus committed Jun 23, 2014
1 parent 4bdadc2 commit d1421a7
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions mojoshader_common.c
Expand Up @@ -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];
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d1421a7

Please sign in to comment.