From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: Re: What's cooking in git.git (Jan 2009, #04; Mon, 19)
Date: Mon, 19 Jan 2009 23:30:30 -0500 [thread overview]
Message-ID: <20090120043030.GD30714@sigill.intra.peff.net> (raw)
In-Reply-To: <7vbpu3r745.fsf@gitster.siamese.dyndns.org>
On Mon, Jan 19, 2009 at 01:13:30AM -0800, Junio C Hamano wrote:
> * jk/color-parse (Sat Jan 17 10:38:46 2009 -0500) 2 commits
> + expand --pretty=format color options
> + color: make it easier for non-config to parse color specs
I posted a revised version of 1/2 based on René's work, but it looks
like you have the original. So here it is on top of what's in next.
-- >8 --
From: René Scharfe <rene.scharfe@lsrfire.ath.cx>
optimize color_parse_mem
Commit 5ef8d77a implemented color_parse_mem, a function for
parsing colors from a non-NUL-terminated string, by simply
allocating a new NUL-terminated string and calling
color_parse. This had a small but measurable speed impact on
a user format that used the advanced color parsing. E.g.,
# uses quick parsing
$ time ./git log --pretty=tformat:'%Credfoo%Creset' >/dev/null
real 0m0.673s
user 0m0.652s
sys 0m0.016s
# uses color_parse_mem
$ time ./git log --pretty=tformat:'%C(red)foo%C(reset)' >/dev/null
real 0m0.692s
user 0m0.660s
sys 0m0.032s
This patch implements color_parse_mem as the primary
function, with color_parse as a wrapper for strings. This
gives comparable timings to the first case above.
Original patch by René. Commit message and debugging by Jeff
King.
Signed-off-by: Jeff King <peff@peff.net>
---
color.c | 38 +++++++++++++++++++++-----------------
1 files changed, 21 insertions(+), 17 deletions(-)
diff --git a/color.c b/color.c
index 54a3da1..915d7a9 100644
--- a/color.c
+++ b/color.c
@@ -41,29 +41,40 @@ static int parse_attr(const char *name, int len)
void color_parse(const char *value, const char *var, char *dst)
{
+ color_parse_mem(value, strlen(value), var, dst);
+}
+
+void color_parse_mem(const char *value, int value_len, const char *var,
+ char *dst)
+{
const char *ptr = value;
+ int len = value_len;
int attr = -1;
int fg = -2;
int bg = -2;
- if (!strcasecmp(value, "reset")) {
+ if (!strncasecmp(value, "reset", len)) {
strcpy(dst, "\033[m");
return;
}
/* [fg [bg]] [attr] */
- while (*ptr) {
+ while (len > 0) {
const char *word = ptr;
- int val, len = 0;
+ int val, wordlen = 0;
- while (word[len] && !isspace(word[len]))
- len++;
+ while (len > 0 && !isspace(word[wordlen])) {
+ wordlen++;
+ len--;
+ }
- ptr = word + len;
- while (*ptr && isspace(*ptr))
+ ptr = word + wordlen;
+ while (len > 0 && isspace(*ptr)) {
ptr++;
+ len--;
+ }
- val = parse_color(word, len);
+ val = parse_color(word, wordlen);
if (val >= -1) {
if (fg == -2) {
fg = val;
@@ -75,7 +86,7 @@ void color_parse(const char *value, const char *var, char *dst)
}
goto bad;
}
- val = parse_attr(word, len);
+ val = parse_attr(word, wordlen);
if (val < 0 || attr != -1)
goto bad;
attr = val;
@@ -115,7 +126,7 @@ void color_parse(const char *value, const char *var, char *dst)
*dst = 0;
return;
bad:
- die("bad color value '%s' for variable '%s'", value, var);
+ die("bad color value '%.*s' for variable '%s'", value_len, value, var);
}
int git_config_colorbool(const char *var, const char *value, int stdout_is_tty)
@@ -191,10 +202,3 @@ int color_fprintf_ln(FILE *fp, const char *color, const char *fmt, ...)
va_end(args);
return r;
}
-
-void color_parse_mem(const char *value, int len, const char *var, char *dst)
-{
- char *tmp = xmemdupz(value, len);
- color_parse(tmp, var, dst);
- free(tmp);
-}
--
1.6.1.335.g0366b.dirty
next prev parent reply other threads:[~2009-01-20 4:32 UTC|newest]
Thread overview: 73+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-01-19 9:13 What's cooking in git.git (Jan 2009, #04; Mon, 19) Junio C Hamano
2009-01-19 11:54 ` Kjetil Barvik
2009-01-19 13:09 ` Johannes Schindelin
2009-01-19 13:08 ` Johannes Schindelin
2009-01-20 4:44 ` Jeff King
2009-01-20 13:51 ` valgrind patches, was " Johannes Schindelin
2009-01-20 14:19 ` Jeff King
2009-01-20 14:50 ` Johannes Schindelin
2009-01-20 15:04 ` [PATCH 1/2] Add valgrind support in test scripts Johannes Schindelin
2009-01-20 15:05 ` [PATCH 2/2] valgrind: ignore ldso errors Johannes Schindelin
2009-01-21 0:12 ` [PATCH 1/2] Add valgrind support in test scripts Jeff King
2009-01-21 0:41 ` Johannes Schindelin
2009-01-21 1:10 ` [PATCH 1/2 v2] " Johannes Schindelin
2009-01-21 1:11 ` [INTERDIFF of PATCH " Johannes Schindelin
2009-01-21 8:48 ` [PATCH " Junio C Hamano
2009-01-21 12:21 ` Johannes Schindelin
2009-01-21 19:02 ` Jeff King
2009-01-21 20:49 ` Johannes Schindelin
2009-01-21 21:53 ` Jeff King
2009-01-21 22:38 ` Johannes Schindelin
2009-01-25 23:18 ` [PATCH 0/3] Valgrind support Johannes Schindelin
2009-01-25 23:18 ` [PATCH v3 1/3] Add valgrind support in test scripts Johannes Schindelin
2009-01-25 23:29 ` Jeff King
2009-01-25 23:35 ` Johannes Schindelin
2009-01-25 23:42 ` Jeff King
2009-01-25 23:19 ` [PATCH v3 2/3] valgrind: ignore ldso and more libz errors Johannes Schindelin
2009-01-25 23:32 ` Jeff King
2009-01-26 0:02 ` Johannes Schindelin
2009-01-26 0:14 ` Jeff King
2009-01-25 23:20 ` [PATCH 3/3] Valgrind support: check for more than just programming errors Johannes Schindelin
2009-01-25 23:42 ` Jeff King
2009-01-26 0:43 ` Johannes Schindelin
2009-01-21 22:31 ` [PATCH] valgrind tests: be super-super paranoid when creating symlinks Johannes Schindelin
2009-01-20 23:24 ` valgrind patches, was Re: What's cooking in git.git (Jan 2009, #04; Mon, 19) Jeff King
2009-01-21 0:10 ` Johannes Schindelin
2009-01-21 0:15 ` Jeff King
2009-01-21 0:28 ` Johannes Schindelin
2009-01-21 0:37 ` Jeff King
2009-01-21 1:26 ` Johannes Schindelin
2009-01-21 1:36 ` [PATCH 2/2 v2] valgrind: ignore ldso errors Johannes Schindelin
2009-01-21 19:09 ` Jeff King
2009-01-21 20:51 ` Johannes Schindelin
2009-01-21 19:07 ` valgrind patches, was Re: What's cooking in git.git (Jan 2009, #04; Mon, 19) Jeff King
2009-01-21 22:17 ` Johannes Schindelin
2009-01-21 23:57 ` Jeff King
2009-01-22 0:42 ` Junio C Hamano
2009-01-22 0:59 ` Jeff King
2009-01-22 5:02 ` Johannes Schindelin
2009-01-22 5:39 ` Jeff King
2009-01-27 2:50 ` Valgrind updates Johannes Schindelin
2009-01-27 3:38 ` Linus Torvalds
2009-01-27 4:26 ` Johannes Schindelin
2009-01-27 4:46 ` Johannes Schindelin
2009-01-27 13:14 ` Mark Brown
2009-01-27 16:54 ` Johannes Schindelin
2009-01-27 18:55 ` Linus Torvalds
2009-01-27 21:52 ` Johannes Schindelin
2009-01-29 1:56 ` Linus Torvalds
2009-01-29 14:22 ` Johannes Schindelin
2009-01-28 23:06 ` Mark Adler
2009-01-28 23:27 ` Johannes Schindelin
2009-01-29 0:15 ` Mark Adler
2009-01-29 14:14 ` Johannes Schindelin
2009-01-29 14:54 ` Johannes Schindelin
2009-01-27 4:48 ` Jeff King
2009-01-27 9:31 ` Johannes Schindelin
2009-01-20 4:30 ` Jeff King [this message]
2009-01-20 4:40 ` What's cooking in git.git (Jan 2009, #04; Mon, 19) Jeff King
2009-01-20 7:04 ` Junio C Hamano
2009-01-20 7:55 ` Johannes Sixt
2009-01-20 14:18 ` Jeff King
2009-01-20 5:17 ` Boyd Stephen Smith Jr.
2009-01-20 8:57 ` Thomas Rast
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=20090120043030.GD30714@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.