Optimize color_parse_mem
commit2c2dc7c82cea66c5030583233c73593e0f5a8fdb
authorRené Scharfe <rene.scharfe@lsrfire.ath.cx>
Tue, 20 Jan 2009 04:30:30 +0000 (19 23:30 -0500)
committerJunio C Hamano <gitster@pobox.com>
Tue, 20 Jan 2009 05:34:46 +0000 (19 21:34 -0800)
tree1c3d0d5ac36121ab6805295d77f32331cba11c1a
parentc002922adce90b69ac56a86eeb77b249afa88eb2
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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
color.c