Tune store_name() fix in a9cb3971c6

By only checking the last-allocated block for space, the amount
off unused memory on the system is increased. This patch alters
things so that the 10 last-allocated blocks are checked. This
stil avoids the O(n^2) explosion but should improve memory efficiency.
This commit is contained in:
Simon Kelley committed 2026-09-02 21:43:49 +01:00
1 parent a9cb3971c6
commit baf85a8f38
1 file changed
+8 -4
+8 -4
View File
@@ -223,14 +223,18 @@ static char *store_name(unsigned int namelen, unsigned int index)
{
struct nameblock *block;
char *ret = NULL;
int i;
if (namelen > NAMEBLOCK_CHARS)
return NULL;
if (hostblocks && hostblocks->index == index && NAMEBLOCK_CHARS - hostblocks->last >= namelen)
/* Check the first few blocks for possible space. This allows efficient memory usage
without blowing up O(n^2) CPU usage which the linked list gets long. */
for (i = 10, block = hostblocks; i != 0 && block; block = block->next, i--)
if (block->index == index && NAMEBLOCK_CHARS - block->last >= namelen)
{
ret = &hostblocks->data[hostblocks->last];
hostblocks->last += namelen;
ret = &block->data[block->last];
block->last += namelen;
return ret;
}