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

[PATCH 1/2] log-tree: simplify digit_in_number

From
Ralf Thielow <ralf.thielow@googlemail.com>
Date
Jul 25, 2010, 17:43 UTC
Message-ID
<1280079798-4993-1-git-send-email-ralf.thielow@googlemail.com>
log-tree: simplify digit_in_number
Simplify the algorithm to resolve the digits in a number.
Signed-off-by: Ralf Thielow <ralf.thielow@googlemail.com>
---
 log-tree.c |   10 ++++------
 1 files changed, 4 insertions(+), 6 deletions(-)
diff --git a/log-tree.c b/log-tree.c
index b46ed3b..95a00a4 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -254,12 +254,10 @@ static void append_signoff(struct strbuf *sb, const char *signoff)
 
 static unsigned int digits_in_number(unsigned int number)
 {
-	unsigned int i = 10, result = 1;
-	while (i <= number) {
-		i *= 10;
-		result++;
-	}
-	return result;
+	int digits = 0;
+	while (number /= 10) 
+		digits++;
+	return digits++;
 }
 
 void get_patch_filename(struct commit *commit, int nr, const char *suffix,
-- 
1.7.0.4
Next: Ralf Thielow
Message 1 of 2 in “log-tree: simplify digit_in_number”
  1. 1/2 log-tree: simplify digit_in_numberRalf Thielow, Jul 25, 2010
  2. 2/2 simplify digit_in_numberRalf Thielow, Jul 25, 2010

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.