From 05fad8df8972def0af73c6f528308220660ba67b Mon Sep 17 00:00:00 2001 From: sebres Date: Fri, 12 Apr 2024 22:55:14 +0000 Subject: minor backport from my core: simple speed-up if searching for the key from hash itself (it is safe to compare needle with an address to key.string); back to mixed identation (removed before) --- generic/tclHash.c | 62 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/generic/tclHash.c b/generic/tclHash.c index 40a855b..4c204a2 100644 --- a/generic/tclHash.c +++ b/generic/tclHash.c @@ -319,40 +319,42 @@ CreateHashEntry( Tcl_CompareHashKeysProc *compareKeysProc = typePtr->compareKeysProc; if (typePtr->flags & TCL_HASH_KEY_DIRECT_COMPARE) { - for (hPtr = tablePtr->buckets[index]; hPtr != NULL; - hPtr = hPtr->nextPtr) { + for (hPtr = tablePtr->buckets[index]; hPtr != NULL; + hPtr = hPtr->nextPtr) { #if TCL_HASH_KEY_STORE_HASH - if (hash != PTR2UINT(hPtr->hash)) { - continue; - } + if (hash != PTR2UINT(hPtr->hash)) { + continue; + } #endif - /* if keys pointers or values are equal */ - if ((key == hPtr->key.oneWordValue) - || compareKeysProc((VOID *) key, hPtr) - ) { - if (newPtr) { - *newPtr = 0; - } - return hPtr; - } - } - } else { - for (hPtr = tablePtr->buckets[index]; hPtr != NULL; - hPtr = hPtr->nextPtr) { + /* if keys pointers or values are equal */ + if ((key == hPtr->key.oneWordValue) + || compareKeysProc((VOID *) key, hPtr) + ) { + if (newPtr) { + *newPtr = 0; + } + return hPtr; + } + } + } else { + for (hPtr = tablePtr->buckets[index]; hPtr != NULL; + hPtr = hPtr->nextPtr) { #if TCL_HASH_KEY_STORE_HASH - if (hash != PTR2UINT(hPtr->hash)) { - continue; - } + if (hash != PTR2UINT(hPtr->hash)) { + continue; + } #endif - /* if keys pointers or values are equal */ - if (compareKeysProc((VOID *) key, hPtr)) { - if (newPtr) { - *newPtr = 0; - } - return hPtr; - } - } - } + /* if needle pointer equals content pointer or values equal */ + if ((key == hPtr->key.string) + || compareKeysProc((VOID *) key, hPtr) + ) { + if (newPtr) { + *newPtr = 0; + } + return hPtr; + } + } + } } else { for (hPtr = tablePtr->buckets[index]; hPtr != NULL; hPtr = hPtr->nextPtr) { -- cgit v0.12 From ae0d35c2744747f5e538c9aa52e21289b7eccfc1 Mon Sep 17 00:00:00 2001 From: sebres Date: Fri, 12 Apr 2024 23:02:15 +0000 Subject: explaination comment --- generic/tclHash.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generic/tclHash.c b/generic/tclHash.c index 189748c..45af73e 100644 --- a/generic/tclHash.c +++ b/generic/tclHash.c @@ -336,7 +336,7 @@ CreateHashEntry( return hPtr; } } - } else { /* no direct compare */ + } else { /* no direct compare - compare key addresses only */ for (hPtr = tablePtr->buckets[index]; hPtr != NULL; hPtr = hPtr->nextPtr) { #if TCL_HASH_KEY_STORE_HASH -- cgit v0.12