From: Vibhav Pant Date: Fri, 10 Feb 2017 17:55:42 +0000 (+0530) Subject: src/bytecode.c: Avoid comparing values unnecessarily in Bswitch X-Git-Tag: emacs-26.0.90~850 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=dcd0e6fe3ae24a716e1f665b12d877681bb8cc21;p=emacs.git src/bytecode.c: Avoid comparing values unnecessarily in Bswitch * 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. --- diff --git a/src/bytecode.c b/src/bytecode.c index ed1eb178468..1ac28110320 100644 --- a/src/bytecode.c +++ b/src/bytecode.c @@ -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;