]> git.eshelyaron.com Git - emacs.git/commitdiff
src/bytecode.c: Avoid comparing values unnecessarily in Bswitch
authorVibhav Pant <vibhavp@gmail.com>
Fri, 10 Feb 2017 17:55:42 +0000 (23:25 +0530)
committerVibhav Pant <vibhavp@gmail.com>
Fri, 10 Feb 2017 17:55:42 +0000 (23:25 +0530)
* src/bytecode.c: (exec_byte_code) While linear searching the jump
  table, compare the value's hash table first to avoid calling
  h->test.cmpfn every time.

src/bytecode.c

index ed1eb178468a2ea1e909fe329796308c2aa04723..1ac281103209fbc714f04ce68304d5790cba7301 100644 (file)
@@ -1429,6 +1429,7 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
             if (h->count <= 5)
               { /* Do a linear search if there are not many cases
                    FIXME: 5 is arbitrarily chosen.  */
+                EMACS_UINT hash_code = h->test.hashfn (&h->test, v1);
                 for (i = 0; i < h->count; i++)
                   {
 #ifdef BYTE_CODE_SAFE
@@ -1439,8 +1440,9 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
                        HASH_TABLE_SIZE (h) == h->count.  */
 
                     if ((EQ (v1, HASH_KEY (h, i)) ||
-                         (h->test.cmpfn &&
-                          h->test.cmpfn (&h->test, v1, HASH_KEY (h, i)))))
+                         (h->test.cmpfn
+                          && hash_code == XUINT (HASH_HASH (h, i))
+                          && h->test.cmpfn (&h->test, v1, HASH_KEY (h, i)))))
                       {
                         op = XINT (HASH_VALUE (h, i));
                         goto op_branch;