summaryrefslogtreecommitdiffstats
path: root/generic/tclHash.c
diff options
context:
space:
mode:
Diffstat (limited to 'generic/tclHash.c')
-rw-r--r--generic/tclHash.c81
1 files changed, 11 insertions, 70 deletions
diff --git a/generic/tclHash.c b/generic/tclHash.c
index 3faadb9..cabf02a 100644
--- a/generic/tclHash.c
+++ b/generic/tclHash.c
@@ -10,7 +10,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclHash.c,v 1.25 2006/08/10 12:15:31 dkf Exp $
+ * RCS: @(#) $Id: tclHash.c,v 1.26 2006/10/22 00:13:29 msofer Exp $
*/
#include "tclInt.h"
@@ -263,75 +263,10 @@ Tcl_FindHashEntry(
Tcl_HashTable *tablePtr, /* Table in which to lookup entry. */
CONST char *key) /* Key to use to find matching entry. */
{
- register Tcl_HashEntry *hPtr;
- Tcl_HashKeyType *typePtr;
- unsigned int hash;
- int index;
-
-#if TCL_PRESERVE_BINARY_COMPATABILITY
- if (tablePtr->keyType == TCL_STRING_KEYS) {
- typePtr = &tclStringHashKeyType;
- } else if (tablePtr->keyType == TCL_ONE_WORD_KEYS) {
- typePtr = &tclOneWordHashKeyType;
- } else if (tablePtr->keyType == TCL_CUSTOM_TYPE_KEYS
- || tablePtr->keyType == TCL_CUSTOM_PTR_KEYS) {
- typePtr = tablePtr->typePtr;
- } else {
- typePtr = &tclArrayHashKeyType;
- }
-#else
- typePtr = tablePtr->typePtr;
- if (typePtr == NULL) {
- Tcl_Panic("called %s on deleted table", "Tcl_FindHashEntry");
- return NULL;
- }
-#endif
-
- if (typePtr->hashKeyProc) {
- hash = typePtr->hashKeyProc (tablePtr, (VOID *) key);
- if (typePtr->flags & TCL_HASH_KEY_RANDOMIZE_HASH) {
- index = RANDOM_INDEX (tablePtr, hash);
- } else {
- index = hash & tablePtr->mask;
- }
- } else {
- hash = (unsigned int) key;
- index = RANDOM_INDEX (tablePtr, hash);
- }
-
- /*
- * Search all of the entries in the appropriate bucket.
- */
- if (typePtr->compareKeysProc) {
- Tcl_CompareHashKeysProc *compareKeysProc = typePtr->compareKeysProc;
- for (hPtr = tablePtr->buckets[index]; hPtr != NULL;
- hPtr = hPtr->nextPtr) {
-#if TCL_HASH_KEY_STORE_HASH
- if (hash != (unsigned int) hPtr->hash) {
- continue;
- }
-#endif
- if (compareKeysProc ((VOID *) key, hPtr)) {
- return hPtr;
- }
- }
- } else {
- for (hPtr = tablePtr->buckets[index]; hPtr != NULL;
- hPtr = hPtr->nextPtr) {
-#if TCL_HASH_KEY_STORE_HASH
- if (hash != (unsigned int) hPtr->hash) {
- continue;
- }
-#endif
- if (key == hPtr->key.oneWordValue) {
- return hPtr;
- }
- }
- }
-
- return NULL;
+ return Tcl_CreateHashEntry(tablePtr, key, NULL);
}
+
/*
*----------------------------------------------------------------------
@@ -412,7 +347,8 @@ Tcl_CreateHashEntry(
}
#endif
if (compareKeysProc ((VOID *) key, hPtr)) {
- *newPtr = 0;
+ if (newPtr)
+ *newPtr = 0;
return hPtr;
}
}
@@ -425,12 +361,17 @@ Tcl_CreateHashEntry(
}
#endif
if (key == hPtr->key.oneWordValue) {
- *newPtr = 0;
+ if (newPtr)
+ *newPtr = 0;
return hPtr;
}
}
}
+ if (!newPtr)
+ return NULL;
+
+
/*
* Entry not found. Add a new one to the bucket.
*/