diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2022-08-26 20:25:34 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2022-08-26 20:25:34 (GMT) |
commit | 8e84ff6bb043a3df9636ba006b8639a3779c52b1 (patch) | |
tree | 207ff6d38c8d659ba3e2dec6fe011b1608ec87f0 /generic/tclHash.c | |
parent | 143111498e3979e4fdec779ec707746b70a56e0c (diff) | |
parent | 17775db55f95232f3821a717f6df97c4a1f3f010 (diff) | |
download | tcl-8e84ff6bb043a3df9636ba006b8639a3779c52b1.zip tcl-8e84ff6bb043a3df9636ba006b8639a3779c52b1.tar.gz tcl-8e84ff6bb043a3df9636ba006b8639a3779c52b1.tar.bz2 |
Merge 8.7
Diffstat (limited to 'generic/tclHash.c')
-rw-r--r-- | generic/tclHash.c | 28 |
1 files changed, 6 insertions, 22 deletions
diff --git a/generic/tclHash.c b/generic/tclHash.c index 3ca269c..5cfc63c 100644 --- a/generic/tclHash.c +++ b/generic/tclHash.c @@ -659,21 +659,16 @@ AllocArrayEntry( Tcl_HashTable *tablePtr, /* Hash table. */ void *keyPtr) /* Key to store in the hash table entry. */ { - int *array = (int *) keyPtr; - int *iPtr1, *iPtr2; Tcl_HashEntry *hPtr; - int count = tablePtr->keyType; - TCL_HASH_TYPE size = sizeof(Tcl_HashEntry) + (count*sizeof(int)) - sizeof(hPtr->key); + TCL_HASH_TYPE count = tablePtr->keyType * sizeof(int); + TCL_HASH_TYPE size = offsetof(Tcl_HashEntry, key) + count; if (size < sizeof(Tcl_HashEntry)) { size = sizeof(Tcl_HashEntry); } hPtr = (Tcl_HashEntry *)Tcl_Alloc(size); - for (iPtr1 = array, iPtr2 = hPtr->key.words; - count > 0; count--, iPtr1++, iPtr2++) { - *iPtr2 = *iPtr1; - } + memcpy(hPtr->key.string, keyPtr, count); Tcl_SetHashValue(hPtr, NULL); return hPtr; @@ -701,20 +696,9 @@ CompareArrayKeys( void *keyPtr, /* New key to compare. */ Tcl_HashEntry *hPtr) /* Existing key to compare. */ { - const int *iPtr1 = (const int *)keyPtr; - const int *iPtr2 = hPtr->key.words; - Tcl_HashTable *tablePtr = hPtr->tablePtr; - int count; + size_t count = hPtr->tablePtr->keyType * sizeof(int); - for (count = tablePtr->keyType; ; count--, iPtr1++, iPtr2++) { - if (count == 0) { - return 1; - } - if (*iPtr1 != *iPtr2) { - break; - } - } - return 0; + return !memcmp(keyPtr, hPtr->key.string, count); } /* @@ -781,7 +765,7 @@ AllocStringEntry( allocsize = sizeof(hPtr->key); } hPtr = (Tcl_HashEntry *)Tcl_Alloc(offsetof(Tcl_HashEntry, key) + allocsize); - memset(hPtr, 0, sizeof(Tcl_HashEntry) + allocsize - sizeof(hPtr->key)); + memset(hPtr, 0, offsetof(Tcl_HashEntry, key) + allocsize); memcpy(hPtr->key.string, string, size); Tcl_SetHashValue(hPtr, NULL); return hPtr; |