mirror of
http://thekelleys.org.uk/git/dnsmasq.git
synced 2026-10-29 12:50:47 +00:00
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:
1 file changed
+8
-4
+8
-4
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user