diff options
| author | sebres <sebres@users.sourceforge.net> | 2024-04-12 22:55:14 (GMT) |
|---|---|---|
| committer | sebres <sebres@users.sourceforge.net> | 2024-04-12 22:55:14 (GMT) |
| commit | 05fad8df8972def0af73c6f528308220660ba67b (patch) | |
| tree | 201efc8de9e0a91f9a62e19104a28f8566ae6dc6 /generic/tclHash.c | |
| parent | d57677488f057b142552a7611ebd5dd23e0cf359 (diff) | |
| download | tcl-05fad8df8972def0af73c6f528308220660ba67b.zip tcl-05fad8df8972def0af73c6f528308220660ba67b.tar.gz tcl-05fad8df8972def0af73c6f528308220660ba67b.tar.bz2 | |
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)
Diffstat (limited to 'generic/tclHash.c')
| -rw-r--r-- | generic/tclHash.c | 62 |
1 files 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) { |
