提交 b79ccafa 编写于 作者: Y Yifan Hao

Hash table cleanup [12/n]

Remove unnecessary allocation for EXT_SIZE (1024 bytes) in
taosHashGetCloneExt. By reading the code, this doesn't seem like
needed.

* Testing
./taosdemo

Spent 87.4217 seconds to insert rows: 100000000, affected rows: 100000000 with 8 thread(s) into test.meters. 1143880.49 records/second

insert delay, avg:      69.22ms, max:     240.04ms, min:      26.19ms
上级 8d3851fc
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
* Macro definition * Macro definition
*/ */
#define EXT_SIZE 1024
#define HASH_MAX_CAPACITY (1024 * 1024 * 16) #define HASH_MAX_CAPACITY (1024 * 1024 * 16)
#define HASH_DEFAULT_LOAD_FACTOR (0.75) #define HASH_DEFAULT_LOAD_FACTOR (0.75)
#define HASH_INDEX(v, c) ((v) & ((c)-1)) #define HASH_INDEX(v, c) ((v) & ((c)-1))
...@@ -139,10 +138,13 @@ static FORCE_INLINE int32_t taosHashCapacity(int32_t length) { ...@@ -139,10 +138,13 @@ static FORCE_INLINE int32_t taosHashCapacity(int32_t length) {
return i; return i;
} }
static FORCE_INLINE SHashNode *doSearchInEntryList(SHashObj *pHashObj, SHashEntry *pe, const void *key, size_t keyLen, uint32_t hashVal) { static FORCE_INLINE SHashNode *
doSearchInEntryList(SHashObj *pHashObj, SHashEntry *pe, const void *key, size_t keyLen, uint32_t hashVal) {
SHashNode *pNode = pe->next; SHashNode *pNode = pe->next;
while (pNode) { while (pNode) {
if ((pNode->keyLen == keyLen) && ((*(pHashObj->equalFp))(GET_HASH_NODE_KEY(pNode), key, keyLen) == 0) && pNode->removed == 0) { if ((pNode->keyLen == keyLen) &&
((*(pHashObj->equalFp))(GET_HASH_NODE_KEY(pNode), key, keyLen) == 0) &&
pNode->removed == 0) {
assert(pNode->hashVal == hashVal); assert(pNode->hashVal == hashVal);
break; break;
} }
...@@ -416,17 +418,13 @@ void* taosHashGetCloneExt(SHashObj *pHashObj, const void *key, size_t keyLen, vo ...@@ -416,17 +418,13 @@ void* taosHashGetCloneExt(SHashObj *pHashObj, const void *key, size_t keyLen, vo
} }
if (*d == NULL) { if (*d == NULL) {
*sz = pNode->dataLen + EXT_SIZE; *sz = pNode->dataLen;
*d = calloc(1, *sz); *d = calloc(1, *sz);
} else if (*sz < pNode->dataLen){ } else if (*sz < pNode->dataLen){
*sz = pNode->dataLen + EXT_SIZE; *sz = pNode->dataLen;
*d = realloc(*d, *sz); *d = realloc(*d, *sz);
} }
memcpy((char *)(*d), GET_HASH_NODE_DATA(pNode), pNode->dataLen); memcpy((char *)(*d), GET_HASH_NODE_DATA(pNode), pNode->dataLen);
// just make runtime happy
if ((*sz) - pNode->dataLen > 0) {
memset((char *)(*d) + pNode->dataLen, 0, (*sz) - pNode->dataLen);
}
data = GET_HASH_NODE_DATA(pNode); data = GET_HASH_NODE_DATA(pNode);
} }
...@@ -507,8 +505,8 @@ int32_t taosHashRemoveWithData(SHashObj *pHashObj, const void *key, size_t keyLe ...@@ -507,8 +505,8 @@ int32_t taosHashRemoveWithData(SHashObj *pHashObj, const void *key, size_t keyLe
// double check after locked // double check after locked
if (pe->num == 0) { if (pe->num == 0) {
assert(pe->next == NULL); assert(pe->next == NULL);
taosHashEntryWUnlock(pHashObj, pe);
taosHashEntryWUnlock(pHashObj, pe);
taosHashRUnlock(pHashObj); taosHashRUnlock(pHashObj);
return -1; return -1;
} }
...@@ -753,7 +751,7 @@ SHashNode *doCreateHashNode(const void *key, size_t keyLen, const void *pData, s ...@@ -753,7 +751,7 @@ SHashNode *doCreateHashNode(const void *key, size_t keyLen, const void *pData, s
pNewNode->keyLen = (uint32_t)keyLen; pNewNode->keyLen = (uint32_t)keyLen;
pNewNode->hashVal = hashVal; pNewNode->hashVal = hashVal;
pNewNode->dataLen = (uint32_t) dsize; pNewNode->dataLen = (uint32_t)dsize;
pNewNode->refCount = 1; pNewNode->refCount = 1;
pNewNode->removed = 0; pNewNode->removed = 0;
pNewNode->next = NULL; pNewNode->next = NULL;
...@@ -899,7 +897,7 @@ void taosHashCancelIterate(SHashObj *pHashObj, void *p) { ...@@ -899,7 +897,7 @@ void taosHashCancelIterate(SHashObj *pHashObj, void *p) {
taosHashReleaseNode(pHashObj, p, &slot); taosHashReleaseNode(pHashObj, p, &slot);
SHashEntry *pe = pHashObj->hashList[slot]; SHashEntry *pe = pHashObj->hashList[slot];
taosHashEntryWUnlock(pHashObj, pe);
taosHashEntryWUnlock(pHashObj, pe);
taosHashRUnlock(pHashObj); taosHashRUnlock(pHashObj);
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册