summaryrefslogtreecommitdiffstats
path: root/generic/tclHash.c
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2012-11-26 16:59:05 (GMT)
committerdgp <dgp@users.sourceforge.net>2012-11-26 16:59:05 (GMT)
commite168187cdd79d76ce92d760218fe7bec7d3dcf32 (patch)
tree47709505e4667682031ba33d50ca2512dd5a1c71 /generic/tclHash.c
parent9ee1f42d143f766f9fafd3eb1d1ac354b15c681d (diff)
parent888f7141151b5b085d0cdc0029121d67a06e7273 (diff)
downloadtcl-e168187cdd79d76ce92d760218fe7bec7d3dcf32.zip
tcl-e168187cdd79d76ce92d760218fe7bec7d3dcf32.tar.gz
tcl-e168187cdd79d76ce92d760218fe7bec7d3dcf32.tar.bz2
merge 8.5
Diffstat (limited to 'generic/tclHash.c')
-rw-r--r--generic/tclHash.c45
1 files changed, 32 insertions, 13 deletions
diff --git a/generic/tclHash.c b/generic/tclHash.c
index a606885..256b073 100644
--- a/generic/tclHash.c
+++ b/generic/tclHash.c
@@ -9,8 +9,6 @@
*
* 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.33.2.1 2008/11/18 07:02:17 nijtmans Exp $
*/
#include "tclInt.h"
@@ -74,6 +72,9 @@ static unsigned int HashStringKey(Tcl_HashTable *tablePtr, VOID *keyPtr);
static Tcl_HashEntry * BogusFind(Tcl_HashTable *tablePtr, const char *key);
static Tcl_HashEntry * BogusCreate(Tcl_HashTable *tablePtr, const char *key,
int *newPtr);
+static Tcl_HashEntry * CreateHashEntry(Tcl_HashTable *tablePtr, const char *key,
+ int *newPtr);
+static Tcl_HashEntry * FindHashEntry(Tcl_HashTable *tablePtr, const char *key);
static void RebuildTable(Tcl_HashTable *tablePtr);
Tcl_HashKeyType tclArrayHashKeyType = {
@@ -186,8 +187,8 @@ Tcl_InitCustomHashTable(
tablePtr->downShift = 28;
tablePtr->mask = 3;
tablePtr->keyType = keyType;
- tablePtr->findProc = Tcl_FindHashEntry;
- tablePtr->createProc = Tcl_CreateHashEntry;
+ tablePtr->findProc = FindHashEntry;
+ tablePtr->createProc = CreateHashEntry;
if (typePtr == NULL) {
/*
@@ -230,8 +231,15 @@ Tcl_FindHashEntry(
Tcl_HashTable *tablePtr, /* Table in which to lookup entry. */
const char *key) /* Key to use to find matching entry. */
{
+ return (*((tablePtr)->findProc))(tablePtr, key);
+}
- return Tcl_CreateHashEntry(tablePtr, key, NULL);
+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);
}
@@ -264,6 +272,17 @@ Tcl_CreateHashEntry(
int *newPtr) /* Store info here telling whether a new entry
* was created. */
{
+ return (*((tablePtr)->createProc))(tablePtr, key, newPtr);
+}
+
+static Tcl_HashEntry *
+CreateHashEntry(
+ Tcl_HashTable *tablePtr, /* Table in which to lookup entry. */
+ const char *key, /* Key to use to find or create matching
+ * entry. */
+ int *newPtr) /* Store info here telling whether a new entry
+ * was created. */
+{
register Tcl_HashEntry *hPtr;
const Tcl_HashKeyType *typePtr;
unsigned int hash;
@@ -415,7 +434,7 @@ Tcl_DeleteHashEntry(
#if TCL_HASH_KEY_STORE_HASH
if (typePtr->hashKeyProc == NULL
|| typePtr->flags & TCL_HASH_KEY_RANDOMIZE_HASH) {
- index = RANDOM_INDEX (tablePtr, entryPtr->hash);
+ index = RANDOM_INDEX(tablePtr, PTR2UINT(entryPtr->hash));
} else {
index = PTR2UINT(entryPtr->hash) & tablePtr->mask;
}
@@ -824,14 +843,14 @@ AllocStringEntry(
{
const char *string = (const char *) keyPtr;
Tcl_HashEntry *hPtr;
- unsigned int size;
+ unsigned int size, allocsize;
- size = sizeof(Tcl_HashEntry) + strlen(string) + 1 - sizeof(hPtr->key);
- if (size < sizeof(Tcl_HashEntry)) {
- size = sizeof(Tcl_HashEntry);
+ allocsize = size = strlen(string) + 1;
+ if (size < sizeof(hPtr->key)) {
+ allocsize = sizeof(hPtr->key);
}
- hPtr = (Tcl_HashEntry *) ckalloc(size);
- strcpy(hPtr->key.string, string);
+ hPtr = (Tcl_HashEntry *) ckalloc(sizeof(Tcl_HashEntry) + allocsize - sizeof(hPtr->key));
+ memcpy(hPtr->key.string, string, size);
hPtr->clientData = 0;
return hPtr;
}
@@ -1045,7 +1064,7 @@ RebuildTable(
#if TCL_HASH_KEY_STORE_HASH
if (typePtr->hashKeyProc == NULL
|| typePtr->flags & TCL_HASH_KEY_RANDOMIZE_HASH) {
- index = RANDOM_INDEX (tablePtr, hPtr->hash);
+ index = RANDOM_INDEX (tablePtr, PTR2UINT(hPtr->hash));
} else {
index = PTR2UINT(hPtr->hash) & tablePtr->mask;
}