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

2 messages from 2010-07-25 to 2010-07-25. Participants: Ralf Thielow.
Thread: https://gitlist.dev/t/24515

## Ralf Thielow, 2010-07-25 17:43

Subject: [PATCH 1/2] log-tree: simplify digit_in_number
Message-ID: <1280079798-4993-1-git-send-email-ralf.thielow@googlemail.com>
URL: https://gitlist.dev/e/1280079798-4993-1-git-send-email-ralf.thielow%40googlemail.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

```

## Ralf Thielow, 2010-07-25 17:43

Subject: [PATCH 2/2] simplify digit_in_number
Message-ID: <1280079798-4993-2-git-send-email-ralf.thielow@googlemail.com>
URL: https://gitlist.dev/e/1280079798-4993-2-git-send-email-ralf.thielow%40googlemail.com
In-Reply-To: <1280079798-4993-1-git-send-email-ralf.thielow@googlemail.com>

```
tree-log: 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 |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/log-tree.c b/log-tree.c
index 95a00a4..c2af716 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -254,10 +254,10 @@ static void append_signoff(struct strbuf *sb, const char *signoff)
 
 static unsigned int digits_in_number(unsigned int number)
 {
-	int digits = 0;
+	int digits = 1;
 	while (number /= 10) 
 		digits++;
-	return digits++;
+	return digits;
 }
 
 void get_patch_filename(struct commit *commit, int nr, const char *suffix,
-- 
1.7.0.4

```
