git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] log-tree: simplify digit_in_number
@ 2010-07-25 17:36 Ralf Thielow
  2010-07-25 17:36 ` [PATCH 2/2] " Ralf Thielow
  2010-07-25 17:46 ` [PATCH 1/2] log-tree: " Jonathan Nieder
  0 siblings, 2 replies; 4+ messages in thread
From: Ralf Thielow @ 2010-07-25 17:36 UTC (permalink / raw)
  To: git; +Cc: Ralf Thielow

---
 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

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

* [PATCH 2/2] simplify digit_in_number
  2010-07-25 17:36 [PATCH 1/2] log-tree: simplify digit_in_number Ralf Thielow
@ 2010-07-25 17:36 ` Ralf Thielow
  2010-07-25 17:46 ` [PATCH 1/2] log-tree: " Jonathan Nieder
  1 sibling, 0 replies; 4+ messages in thread
From: Ralf Thielow @ 2010-07-25 17:36 UTC (permalink / raw)
  To: git; +Cc: Ralf Thielow

---
 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

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

* [PATCH 1/2] log-tree: simplify digit_in_number
@ 2010-07-25 17:43 Ralf Thielow
  0 siblings, 0 replies; 4+ messages in thread
From: Ralf Thielow @ 2010-07-25 17:43 UTC (permalink / raw)
  To: git; +Cc: Ralf Thielow

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

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

* Re: [PATCH 1/2] log-tree: simplify digit_in_number
  2010-07-25 17:36 [PATCH 1/2] log-tree: simplify digit_in_number Ralf Thielow
  2010-07-25 17:36 ` [PATCH 2/2] " Ralf Thielow
@ 2010-07-25 17:46 ` Jonathan Nieder
  1 sibling, 0 replies; 4+ messages in thread
From: Jonathan Nieder @ 2010-07-25 17:46 UTC (permalink / raw)
  To: Ralf Thielow; +Cc: git

Ralf Thielow wrote:

> +++ 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++;

I think you mean "return ++digits;".

But other questions come to mind first:

 - What is the motivation?  How did this come up and what does your change
   improve?

 - Why rewrite this in one patch, only to rewrite it again?

Hope that helps,
Jonathan

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

end of thread, other threads:[~2010-07-25 17:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-25 17:36 [PATCH 1/2] log-tree: simplify digit_in_number Ralf Thielow
2010-07-25 17:36 ` [PATCH 2/2] " Ralf Thielow
2010-07-25 17:46 ` [PATCH 1/2] log-tree: " Jonathan Nieder
  -- strict thread matches above, loose matches on Subject: below --
2010-07-25 17:43 Ralf Thielow

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).