[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 2/3] getcwd-lgpl: new module
From: |
Bruno Haible |
Subject: |
Re: [PATCH 2/3] getcwd-lgpl: new module |
Date: |
Tue, 26 Apr 2011 12:38:26 +0200 |
User-agent: |
KMail/1.9.9 |
Eric Blake wrote:
> + do
> + {
> + tmp = buf;
> + if (first)
> + {
> + size = size ? size : 4096;
> + first = false;
> + }
> + else
> + {
> + size <<= 1;
> + }
> + if ((buf = realloc (tmp, size)) == NULL)
A further hint for optimization:
In the case buf == NULL && size == 0, and when _usually_ the pathname is
small (that's the most frequent case), you are doing a malloc() of 4 KB
followed by a realloc() for shrinking. It would be more efficient to use
a stack-allocated temporary buffer, like
char stack_buf[1024];
in lib/careadlinkat.c.
Bruno
--
In memoriam Heinrich Conradi <http://de.wikipedia.org/wiki/Heinrich_Conradi>