Skip to content
Tcl Source Code View Ticket
Login

View Ticket

More efficient Tcl_FindHashEntry()

Open236d18f49ba2bd9b98b0906b321fe9ca4a60e6ddCreated 2 years agoUpdated 2 years ago
Descriptionwiki2025-04-11 10:32:40
The function Tcl_FindHashEntry() is implemented like:
#define Tcl_FindHashEntry(tablePtr, key) \
       (*((tablePtr)->findProc))(tablePtr, (const char *)(key))
while the findProc is implemented as:
 static Tcl_HashEntry *
 FindHashEntry(
     Tcl_HashTable *tablePtr,   /* Table in which to lookup entry. */
     const char *key)           /* Key to use to find matching entry. */
 {
    return CreateHashEntry(tablePtr, key, NULL);
 }
This means we can do better. Why not just call the createProc directly with it's last NULL parameter (which means don't create anything)

This also means that findProc is not used any more, and could be removed altogether. Only .. we cannot remove it yet, because it might be used by Tcl 9.0-compiled extensions.

Since the Tcl_HashTable content is not documented, this is 100% upwards and downwards compatible.

Referenced by1
apnadkarnimarkdown2025-04-12 03:17:49

Will this patch not preclude possible future internal implementation changes where find is no longer implemented through create?

Looking at generated code, it saves one jump. Not sure it is worth precluding future changes, however unlikely they might be. IMO.

jan.nijtmanswiki2025-04-13 22:27:59

Implementation is complete now. My goal was two things:

- Allow the newPtr value to be NULL, meaning "I'm not interested in this" - Implement Tcl_AttemptCreateHashEntry() (in a separate branch)

The second addition means that a TIP needs to be written anyway, so I an put this improvement in it as well.

Log in (anonymous is fine) to add a comment.