Hi, On Sun, 18 Mar 2007, Linus Torvalds wrote:I felt a little left out in all that performance slashing, and so I thought maybe, just maybe, a small change in xdl_hash_record() can do wonders (since it _is_ really simple, but still takes almost a 6th of the CPU time). I don't have a proper test case setup, so maybe you want to try this: -- snipsnap -- [PATCH] xdiff/xutils.c(xdl_hash_record): factor out whitespace handling Since in at least one use case, xdl_hash_record() takes over 15% of the CPU time, it makes sense to even micro-optimize it. For many cases, no whitespace special handling is needed, and in these cases we should not even bother to check for whitespace in _every_ iteration of the loop. Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> --- Please do not consider this patch _unless_ it is proven to enhance the profile statistics substantially. xdiff/xutils.c | 22 ++++++++++++++++++++-- 1 files changed, 20 insertions(+), 2 deletions(-) diff --git a/xdiff/xutils.c b/xdiff/xutils.c index 3653864..bf91c0f 100644 --- a/xdiff/xutils.c +++ b/xdiff/xutils.c @@ -236,12 +236,13 @@ int xdl_recmatch(const char *l1, long s1, const char *l2, long s2, long flags) return 0; } -unsigned long xdl_hash_record(char const **data, char const *top, long flags) { +static unsigned long xdl_hash_record_with_whitespace(char const **data, + char const *top, long flags) { unsigned long ha = 5381; char const *ptr = *data; for (; ptr < top && *ptr != '\n'; ptr++) { - if (isspace(*ptr) && (flags & XDF_WHITESPACE_FLAGS)) { + if (isspace(*ptr)) { const char *ptr2 = ptr; while (ptr + 1 < top && isspace(ptr[1]) && ptr[1] != '\n') @@ -270,6 +271,23 @@ unsigned long xdl_hash_record(char const **data, char const *top, long flags) { } +unsigned long xdl_hash_record(char const **data, char const *top, long flags) { + unsigned long ha = 5381; + char const *ptr = *data; + + if (flags & XDF_WHITESPACE_FLAGS) + return xdl_hash_record_with_whitespace(data, top, flags); + + for (; ptr < top && *ptr != '\n'; ptr++) { + ha += (ha << 5); + ha ^= (unsigned long) *ptr; + } + *data = ptr < top ? ptr + 1: ptr; + + return ha; +} + + unsigned int xdl_hashbits(unsigned int size) { unsigned int val = 1, bits = 0; - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
| Linus Torvalds | Re: O_DIRECT question |
| Greg KH | [GIT PATCH] driver core patches against 2.6.24 |
| Dave Airlie | Re: [2.6.25-rc6] possible regression: X server dying |
| Florian Schmidt | blacklist kernel boot option |
git: | |
| Petr Baudis | repo.or.cz wishes? |
| Jon Smirl | ! [rejected] master -> master (non-fast forward) |
| Matthieu Moy | [BUG] git-svn dcommit fails (connection closed unexpectedly) |
| Jakub Narebski | Git User's Survey 2007 partial summary |
| Ondřej Surý | openbgp not exporing ipv6 to routing tables |
| Nick Guenther | Re: Real men don't attack straw men |
| Christophe Rioux | OpenBSD as host for VMWare Server |
| Bambero | two wan interfaces |
| Warner Losh | Re: SMP re-eetrancy in "bottom half" drivers |
| Martin Husemann | Re: Prototype kernel continuation-passing for NetBSD |
| Martin Husemann | Dynamic registry of ehternet frame types |
| der Mouse | Re: file id alignment |
