[PATCH] log-tree: simplify digit_in_number
- From
Ralf Thielow <ralf.thielow@googlemail.com>
- Date
- Jul 25, 2010, 18:31 UTC
- Message-ID
- <1280082712-5760-1-git-send-email-ralf.thielow@googlemail.com>
Make the algorithm to get the digits of a number more easily.
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..c7cfcf4 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 = 1; + while (number /= 10) + digits++; + return digits; } void get_patch_filename(struct commit *commit, int nr, const char *suffix,
-- 1.7.0.4