From: Ralf Thielow <ralf.thielow@googlemail.com>
To: git@vger.kernel.org
Cc: Ralf Thielow <ralf.thielow@googlemail.com>
Subject: [PATCH] log-tree: simplify digit_in_number
Date: Sun, 25 Jul 2010 20:31:52 +0200 [thread overview]
Message-ID: <1280082712-5760-1-git-send-email-ralf.thielow@googlemail.com> (raw)
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
next reply other threads:[~2010-07-25 18:32 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-25 18:31 Ralf Thielow [this message]
-- strict thread matches above, loose matches on Subject: below --
2010-07-25 17:16 [PATCH] log-tree: simplify digit_in_number Ralf Thielow
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1280082712-5760-1-git-send-email-ralf.thielow@googlemail.com \
--to=ralf.thielow@googlemail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).