Thread (35 messages) flat view 35 messages, 5 authors, 2016-06-15

Re: [PATCH v2 01/11] builtin/pack-objects.c: change check_pbase_path() to use ALLOC_GROW()

From: Michael Haggerty <hidden>
Date: 2016-06-15 23:00:06

On 02/28/2014 01:40 PM, Duy Nguyen wrote:
On Fri, Feb 28, 2014 at 7:32 PM, Duy Nguyen [off-list ref] wrote:
quoted
quoted
        done_pbase_paths_num++;
If you move this up one line, then you don't have to "+ 1" in ALLOC_GROW
same comment to a few other patches. The rest of your series looks good.
Duy,

The example in Documentation/technical/api-allocation-growing.txt does
it the same way as Dmitry:

    ALLOC_GROW(item, nr + 1, alloc);
    item[nr++] = value you like;

The alternative,

    nr++;
    ALLOC_GROW(item, nr, alloc);
    item[nr] = value you like;

is an extra line, which is at least a small argument for the variant
shown in the docs.  (Since ALLOC_GROW is a macro, it is not OK to use
"++nr" as its second argument.)  Personally, I also prefer the shorter
version.  The line

    item[nr++] = value

is an easy-to-recognize idiom, and

    ALLOC_GROW(item, nr + 1, alloc);

somehow makes it more transparent by how much more space will be needed.

So my vote is that the patches are OK the way Dmitry wrote them (mind, I
have only read through 05/11 so far).

Michael

-- 
Michael Haggerty
mhagger@alum.mit.edu
http://softwareswirl.blogspot.com/
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help