From 97d0b74a49f0c81c3f9673c1a17721ac0624c3df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Fri, 25 Mar 2011 16:34:20 +0700 Subject: Improve tree_entry_interesting() handling code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit t_e_i() can return -1 or 2 to early shortcut a search. Current code may use up to two variables to handle it. One for saving return value from t_e_i temporarily, one for saving return code 2. The second variable is not needed. If we make sure the first variable does not change until the next t_e_i() call, then we can do something like this: int ret = 0; while (...) { if (ret != 2) { ret = t_e_i(); if (ret < 0) /* no longer interesting */ break; if (ret == 0) /* skip this round */ continue; } /* ret > 0, interesting */ } Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- list-objects.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'list-objects.c') diff --git a/list-objects.c b/list-objects.c index 61f6cc98d..cf9dbe23e 100644 --- a/list-objects.c +++ b/list-objects.c @@ -68,7 +68,7 @@ static void process_tree(struct rev_info *revs, struct tree_desc desc; struct name_entry entry; struct name_path me; - int all_interesting = (revs->diffopt.pathspec.nr == 0); + int match = revs->diffopt.pathspec.nr == 0 ? 2 : 0; int baselen = base->len; if (!revs->tree_objects) @@ -85,7 +85,7 @@ static void process_tree(struct rev_info *revs, me.elem = name; me.elem_len = strlen(name); - if (!all_interesting) { + if (!match) { strbuf_addstr(base, name); if (base->len) strbuf_addch(base, '/'); @@ -94,17 +94,13 @@ static void process_tree(struct rev_info *revs, init_tree_desc(&desc, tree->buffer, tree->size); while (tree_entry(&desc, &entry)) { - if (!all_interesting) { - int showit = tree_entry_interesting(&entry, - base, 0, - &revs->diffopt.pathspec); - - if (showit < 0) + if (match != 2) { + match = tree_entry_interesting(&entry, base, 0, + &revs->diffopt.pathspec); + if (match < 0) break; - else if (!showit) + if (match == 0) continue; - else if (showit == 2) - all_interesting = 1; } if (S_ISDIR(entry.mode)) -- cgit v1.2.1