Re: [PATCH v2] cache_tree_find(): remove redundant checks

2014-03-05 Thread Junio C Hamano
Junio C Hamano gits...@pobox.com writes: Michael Haggerty mhag...@alum.mit.edu writes: I really wish we could mix declarations with statements because I think it is a big help to readability. ... Unfortunately, I think we are in violent disagreement. After re-reading the above, I realize

[PATCH v2] cache_tree_find(): remove redundant checks

2014-03-04 Thread Michael Haggerty
The beginning of the loop ensures that slash can never be NULL. So don't keep checking whether it is NULL later in the loop. Furthermore, there is no need for an early return it; from the loop if slash points at the end of the string, because that is exactly what will happen when the while

Re: [PATCH v2] cache_tree_find(): remove redundant checks

2014-03-04 Thread David Kastrup
Michael Haggerty mhag...@alum.mit.edu writes: The beginning of the loop ensures that slash can never be NULL. So don't keep checking whether it is NULL later in the loop. Furthermore, there is no need for an early return it; from the loop if slash points at the end of the string,

Re: [PATCH v2] cache_tree_find(): remove redundant checks

2014-03-04 Thread Michael Haggerty
On 03/04/2014 10:40 AM, David Kastrup wrote: Michael Haggerty mhag...@alum.mit.edu writes: The beginning of the loop ensures that slash can never be NULL. So don't keep checking whether it is NULL later in the loop. Furthermore, there is no need for an early return it; from the

Re: [PATCH v2] cache_tree_find(): remove redundant checks

2014-03-04 Thread David Kastrup
Michael Haggerty mhag...@alum.mit.edu writes: BTW, I purposely didn't use a for loop at the end (even though I usually like them) because I wanted to keep it prominent that path is being updated to the value of slash. Putting that assignment in a for loop makes it easy to overlook because it

Re: [PATCH v2] cache_tree_find(): remove redundant checks

2014-03-04 Thread Junio C Hamano
Michael Haggerty mhag...@alum.mit.edu writes: while (*path) { - const char *slash; struct cache_tree_sub *sub; + const char *slash = strchr(path, '/'); - slash = strchr(path, '/'); if (!slash)

Re: [PATCH v2] cache_tree_find(): remove redundant checks

2014-03-04 Thread Michael Haggerty
On 03/04/2014 10:05 PM, Junio C Hamano wrote: Michael Haggerty mhag...@alum.mit.edu writes: while (*path) { -const char *slash; struct cache_tree_sub *sub; +const char *slash = strchr(path, '/'); -slash = strchr(path, '/');

Re: [PATCH v2] cache_tree_find(): remove redundant checks

2014-03-04 Thread Junio C Hamano
Michael Haggerty mhag...@alum.mit.edu writes: Isn't the above a strchrnul()? Oh, cool, I never realized that this GNU extension was blessed for use in Git. Will change. We do have our own fallbacks for non-glibc platforms, so it should be safe. Combining a freestanding decl with

Re: [PATCH v2] cache_tree_find(): remove redundant checks

2014-03-04 Thread David Kastrup
Junio C Hamano gits...@pobox.com writes: Michael Haggerty mhag...@alum.mit.edu writes: while (*path) { -const char *slash; struct cache_tree_sub *sub; +const char *slash = strchr(path, '/'); -slash = strchr(path, '/');