summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 57584d9)
raw | patch | inline | side by side (parent: 57584d9)
author | Johannes Schindelin <Johannes.Schindelin@gmx.de> | |
Tue, 20 Mar 2007 03:05:10 +0000 (04:05 +0100) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Tue, 20 Mar 2007 05:17:25 +0000 (22:17 -0700) |
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>
Signed-off-by: Junio C Hamano <junkio@cox.net>
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>
Signed-off-by: Junio C Hamano <junkio@cox.net>
xdiff/xutils.c | patch | blob | history |
diff --git a/xdiff/xutils.c b/xdiff/xutils.c
index 3653864e4bf704c024453df8d9abf26d89b4778d..bf91c0f73c658637d078ac93226148faa3bb0dc4 100644 (file)
--- 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;