git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] cache_tree_find(): remove redundant check in while condition
@ 2014-03-03 16:08 Michael Haggerty
  2014-03-03 16:32 ` David Kastrup
  0 siblings, 1 reply; 4+ messages in thread
From: Michael Haggerty @ 2014-03-03 16:08 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, Michael Haggerty

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
A trivial little cleanup.

 cache-tree.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/cache-tree.c b/cache-tree.c
index 0bbec43..7f63c23 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -565,7 +565,7 @@ static struct cache_tree *cache_tree_find(struct cache_tree *it, const char *pat
 			return NULL;
 		it = sub->cache_tree;
 		if (slash)
-			while (*slash && *slash == '/')
+			while (*slash == '/')
 				slash++;
 		if (!slash || !*slash)
 			return it; /* prefix ended with slashes */
-- 
1.9.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] cache_tree_find(): remove redundant check in while condition
  2014-03-03 16:08 [PATCH] cache_tree_find(): remove redundant check in while condition Michael Haggerty
@ 2014-03-03 16:32 ` David Kastrup
  2014-03-03 17:07   ` Michael Haggerty
  0 siblings, 1 reply; 4+ messages in thread
From: David Kastrup @ 2014-03-03 16:32 UTC (permalink / raw)
  To: Michael Haggerty; +Cc: Junio C Hamano, git

Michael Haggerty <mhagger@alum.mit.edu> writes:

> Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
> ---
> A trivial little cleanup.
>
>  cache-tree.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/cache-tree.c b/cache-tree.c
> index 0bbec43..7f63c23 100644
> --- a/cache-tree.c
> +++ b/cache-tree.c
> @@ -565,7 +565,7 @@ static struct cache_tree *cache_tree_find(struct cache_tree *it, const char *pat
>  			return NULL;
>  		it = sub->cache_tree;
>  		if (slash)
> -			while (*slash && *slash == '/')
> +			while (*slash == '/')
>  				slash++;
>  		if (!slash || !*slash)
>  			return it; /* prefix ended with slashes */

That seems dragging around a NULL slash a lot.  How about not checking
for it multiple times?

		if (!slash)
                	return it;
		while (*slash == '/')
			slash++;
		if (!*slash)
			return it; /* prefix ended with slashes */

As a bonus, the comment appears to be actually correct.  Attempting to
verify its correctness by seeing whether a non-NULL slash is guaranteed
to really end with slashes, we find the following code above for
defining slash:

                slash = strchr(path, '/');
                if (!slash)
                        slash = path + strlen(path);

So it is literally impossible for slash to ever be NULL and all the
checking is nonsensical.  In addition, "prefix ended with slashes" does
not seem overly convincing when this code path is reached whether or not
there is a slash at all (I am not sure about it: it depends on the
preceding find_subtree to some degree).

So perhaps all of that should just be

		while (*slash == '/')
			slash++;
		if (!*slash)
			return it;

-- 
David Kastrup

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] cache_tree_find(): remove redundant check in while condition
  2014-03-03 16:32 ` David Kastrup
@ 2014-03-03 17:07   ` Michael Haggerty
  2014-03-03 17:25     ` David Kastrup
  0 siblings, 1 reply; 4+ messages in thread
From: Michael Haggerty @ 2014-03-03 17:07 UTC (permalink / raw)
  To: David Kastrup; +Cc: Junio C Hamano, git

On 03/03/2014 05:32 PM, David Kastrup wrote:
> [...]
> So perhaps all of that should just be
> 
> 		while (*slash == '/')
> 			slash++;
> 		if (!*slash)
> 			return it;
> 

I just fixed a little thing that caught my eye.  You OWNED it.  You are
absolutely right.

Will you prepare a patch or would you like me to do it?

Michael

-- 
Michael Haggerty
mhagger@alum.mit.edu
http://softwareswirl.blogspot.com/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] cache_tree_find(): remove redundant check in while condition
  2014-03-03 17:07   ` Michael Haggerty
@ 2014-03-03 17:25     ` David Kastrup
  0 siblings, 0 replies; 4+ messages in thread
From: David Kastrup @ 2014-03-03 17:25 UTC (permalink / raw)
  To: Michael Haggerty; +Cc: Junio C Hamano, git

Michael Haggerty <mhagger@alum.mit.edu> writes:

> On 03/03/2014 05:32 PM, David Kastrup wrote:
>> [...]
>> So perhaps all of that should just be
>> 
>> 		while (*slash == '/')
>> 			slash++;
>> 		if (!*slash)
>> 			return it;
>> 
>
> I just fixed a little thing that caught my eye.  You OWNED it.  You are
> absolutely right.
>
> Will you prepare a patch or would you like me to do it?

Feel free.  I really should be finishing some other patches instead...

-- 
David Kastrup

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-03-03 17:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-03 16:08 [PATCH] cache_tree_find(): remove redundant check in while condition Michael Haggerty
2014-03-03 16:32 ` David Kastrup
2014-03-03 17:07   ` Michael Haggerty
2014-03-03 17:25     ` David Kastrup

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).