diff: defeat gcc's optimization
authorDenys Vlasenko <vda.linux@googlemail.com>
Mon, 18 Jan 2010 04:22:34 +0000 (05:22 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Mon, 18 Jan 2010 04:22:34 +0000 (05:22 +0100)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
editors/diff.c

index af6917a0309a24fe32541d43c2e5c8daf393eb84..b89bbc1dc66a6c65451fd98703ca4a2df0b6d810 100644 (file)
@@ -435,7 +435,10 @@ static int *create_J(FILE_and_pos_t ft[2], int nlen[2], off_t *ix[2])
                        tok = read_token(&ft[i], tok);
                        if (!(tok & TOK_EMPTY)) {
                                /* Hash algorithm taken from Robert Sedgewick, Algorithms in C, 3d ed., p 578. */
-                               hash = hash * 128 - hash + TOK2CHAR(tok);
+                               /*hash = hash * 128 - hash + TOK2CHAR(tok);
+                                * gcc insists on optimizing above to "hash * 127 + ...", thus... */
+                               unsigned o = hash - TOK2CHAR(tok);
+                               hash = hash * 128 - o; /* we want SPEED here */
                                continue;
                        }
                        if (nlen[i]++ == sz) {