git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] remove unnecessary loop

From
LYLiu Yubao <yubao.liu@gmail.com>
Date
May 8, 2007, 03:18 UTC
Message-ID
<463FEC07.8080605@gmail.com>
Hi,
   Here is a minor optimization, the involved second "for" loop doesn't
need to start from beginning.
Signed-off-by: Liu Yubao <yubao.liu@gmail.com>
---
 builtin-add.c |    9 ++++-----
 1 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/builtin-add.c b/builtin-add.c
index 5e6748f..9d10fdc 100644
--- a/builtin-add.c
+++ b/builtin-add.c
@@ -239,20 +239,19 @@ int cmd_add(int argc, const char **argv, const char *prefix)
 		die("index file corrupt");
 
 	if (!ignored_too) {
-		int has_ignored = 0;
 		for (i = 0; i < dir.nr; i++)
 			if (dir.entries[i]->ignored)
-				has_ignored = 1;
-		if (has_ignored) {
+				break;
+		if (i < dir.nr) {
 			fprintf(stderr, ignore_warning);
-			for (i = 0; i < dir.nr; i++) {
+			do {
 				if (!dir.entries[i]->ignored)
 					continue;
 				fprintf(stderr, "%s", dir.entries[i]->name);
 				if (dir.entries[i]->ignored_dir)
 					fprintf(stderr, " (directory)");
 				fputc('\n', stderr);
-			}
+			} while (++i < dir.nr);
 			fprintf(stderr,
 				"Use -f if you really want to add them.\n");
 			exit(1);
-- 
1.5.2.rc0.95.ga0715-dirty
Next: Liu Yubao
Message 1 of 9 in “remove unnecessary loop”
  1. remove unnecessary loopLiu Yubao, May 8, 2007
  2. Liu YubaoMay 8, 2007
  3. Junio C HamanoMay 8, 2007
  4. Alex RiesenMay 8, 2007
  5. Jan HudecMay 8, 2007
  6. Alex RiesenMay 8, 2007
  7. Eric BlakeMay 8, 2007
  8. Jan HudecMay 8, 2007
  9. Liu YubaoMay 9, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.