You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by bu...@apache.org on 2014/03/21 13:22:26 UTC

[Bug 56297] Attempted optimisation does not (improve performance)

https://issues.apache.org/bugzilla/show_bug.cgi?id=56297

--- Comment #1 from Thomas Schodt <ap...@xenoc.demon.co.uk> ---
Patch tested on linux.

$ svn diff jk_map.c
Index: jk_map.c
===================================================================
--- jk_map.c    (revision 1579918)
+++ jk_map.c    (working copy)
@@ -36,8 +36,8 @@
 #define JK_MAP_REFERENCE    (".reference")
 #define JK_MAP_REFERENCE_SZ (strlen(JK_MAP_REFERENCE))

-/* Compute the "checksum" for a key, consisting of the first
- * 4 bytes, packed into an int.
+/* Compute the "checksum" for a key, consisting of
+ * a digest of the string (same as java hashcode).
  * This checksum allows us to do a single integer
  * comparison as a fast check to determine whether we can
  * skip a strcmp
@@ -45,23 +45,13 @@
 #define COMPUTE_KEY_CHECKSUM(key, checksum)    \
 {                                              \
     const char *k = (key);                     \
-    unsigned int c = (unsigned int)*k;         \
-    (checksum) = c;                            \
-    (checksum) <<= 8;                          \
-    if (c) {                                   \
-        c = (unsigned int)*++k;                \
-        checksum |= c;                         \
+    (checksum) = 0;                            \
+    unsigned int c = (unsigned int)*k++;       \
+    while(c) {                                 \
+        (checksum) *= 31;                      \
+        (checksum) += c;                       \
+        c = (unsigned int)*k++;                \
     }                                          \
-    (checksum) <<= 8;                          \
-    if (c) {                                   \
-        c = (unsigned int)*++k;                \
-        checksum |= c;                         \
-    }                                          \
-    (checksum) <<= 8;                          \
-    if (c) {                                   \
-        c = (unsigned int)*++k;                \
-        checksum |= c;                         \
-    }                                          \
 }

 static volatile int global_map_id = 0;

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org