bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: canonicalize_filename_mode memory usage


From: Jim Meyering
Subject: Re: canonicalize_filename_mode memory usage
Date: Sat, 19 Dec 2009 15:55:49 +0100

Eric Blake wrote:
> Sergey Poznyakoff <gray <at> gnu.org.ua> writes:
>
>> A user of tar reported a suboptimal memory usage by the
>> canonicalize_filename_mode.  Attached is the patch he
>> proposed.  Any comments?
>
> Who do we use as --author and/or reporter in the git commit?  The patch first
> appeared on the tar list in an email by Solar Designer, but it is not clear
> whether he wrote it, or whether we should attribute yet some other person.
>
>>    *dest = '\0';
>>
>> +  actual_size = strlen(rname) + 1;
>
> Quite wasteful.  Rather than calling strlen and redoing an O(n) walk of the
> string, the actual length can be obtained via O(1) calculation using known
> values.
>
>> +  if (rname_limit - rname > actual_size)
>> +    rname = xrealloc (rname, actual_size);
>
> For that matter, the temporary variable actual_size is not even needed.  I'd
> write the patch as just a 2-line addition:
>
> if (rname_limit != dest + 1)
>   rname = xrealloc (rname, dest - rname + 1);

Yes, that is better.
You're welcome to make that change.
Thanks!

> But yes, it is probably a good idea to use the xrealloc to avoid the memory
> waste, since 4k is disproportionately larger than the typical canonical name,
> unless Jim has any other preferences as module owner.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]