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

2014-03-05 Thread Junio C Hamano
David Kastrup writes: > Junio C Hamano writes: > >> Michael Haggerty 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-05 Thread Junio C Hamano
Junio C Hamano writes: > Michael Haggerty 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 that my statement may have soun

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

2014-03-04 Thread David Kastrup
Junio C Hamano writes: > Michael Haggerty 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 Junio C Hamano
Michael Haggerty 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 intializer assignment t

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 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 writes: > while (*path) { > - const char *slash; > struct cache_tree_sub *sub; > + const char *slash = strchr(path, '/'); > > - slash = strchr(path, '/'); > if (!slash) > slash = path +

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

2014-03-04 Thread David Kastrup
Michael Haggerty 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 puts "path" in

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 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 i

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

2014-03-04 Thread David Kastrup
Michael Haggerty 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, because that > i

[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