If the very first string added to the string cache is more than
half the maximum size, we failed when moving the only strcache
buffer to the full list.
for (; *spp != NULL; spp = &(*spp)->next)
if ((*spp)->bytesfree > sz)
break;
+ sp = *spp;
/* If nothing is big enough, make a new cache at the front. */
- sp = *spp;
if (sp == NULL)
{
sp = new_cache (&strcache, BUFSIZE);
- spp = &sp;
+ spp = &strcache;
}
/* Add the string to this cache. */
/* If the amount free in this cache is less than the average string size,
consider it full and move it to the full list. */
- if (sp->bytesfree < (total_size / total_strings) + 1)
+ if (total_strings > 20 && sp->bytesfree < (total_size / total_strings) + 1)
{
- *spp = (*spp)->next;
+ *spp = sp->next;
sp->next = fullcache;
fullcache = sp;
}