Skip to content

Commit 7f5e98f

Browse files
committed
decoder: Optimise creating reused key hash table
1 parent 5081a1c commit 7f5e98f

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

src/simdjson_decoder.cpp

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -223,22 +223,22 @@ static zend_always_inline void simdjson_release_reused_key_strings(HashTable *de
223223
} while (++p != end);
224224
}
225225

226-
static zend_always_inline void simdjson_init_reused_key_strings(HashTable *dedup_key_strings) {
227-
if (UNEXPECTED(dedup_key_strings->nTableSize == 0)) {
228-
// hash table is not initialized yet
229-
zend_hash_init(dedup_key_strings, SIMDJSON_DEDUP_STRING_COUNT, NULL, NULL, 0);
226+
static zend_always_inline void simdjson_init_reused_key_strings(HashTable *ht) {
227+
if (UNEXPECTED(ht->nTableSize == 0)) {
228+
// zend_hash_init
229+
ht->nNumUsed = 0;
230+
ht->nTableSize = SIMDJSON_DEDUP_STRING_COUNT;
230231
// zend_hash_real_init_mixed
231232
void * data = emalloc(HT_SIZE_EX(SIMDJSON_DEDUP_STRING_COUNT, HT_SIZE_TO_MASK(SIMDJSON_DEDUP_STRING_COUNT)));
232-
dedup_key_strings->nTableMask = HT_SIZE_TO_MASK(SIMDJSON_DEDUP_STRING_COUNT);
233-
HT_SET_DATA_ADDR(dedup_key_strings, data);
234-
HT_HASH_RESET(dedup_key_strings);
235-
} else if (dedup_key_strings->nNumUsed > SIMDJSON_DEDUP_STRING_COUNT / 2) {
233+
ht->nTableMask = HT_SIZE_TO_MASK(SIMDJSON_DEDUP_STRING_COUNT);
234+
HT_SET_DATA_ADDR(ht, data);
235+
HT_HASH_RESET(ht);
236+
} else if (ht->nNumUsed > SIMDJSON_DEDUP_STRING_COUNT / 2) {
236237
// more than half of hash table is already full, cleanup
237-
simdjson_release_reused_key_strings(dedup_key_strings);
238-
ZEND_ASSERT(dedup_key_strings->nTableMask == HT_SIZE_TO_MASK(SIMDJSON_DEDUP_STRING_COUNT));
239-
HT_HASH_RESET(dedup_key_strings);
240-
dedup_key_strings->nNumUsed = 0;
241-
dedup_key_strings->nNumOfElements = 0;
238+
simdjson_release_reused_key_strings(ht);
239+
ZEND_ASSERT(ht->nTableMask == HT_SIZE_TO_MASK(SIMDJSON_DEDUP_STRING_COUNT));
240+
HT_HASH_RESET(ht);
241+
ht->nNumUsed = 0;
242242
}
243243
}
244244

@@ -272,7 +272,6 @@ static zend_always_inline zend_string* simdjson_dedup_key(HashTable *ht, const c
272272
return key;
273273
} else {
274274
idx = ht->nNumUsed++;
275-
ht->nNumOfElements++;
276275
p = ht->arData + idx;
277276
p->key = simdjson_string_init(str, len); // initialize new string for key
278277
GC_ADDREF(p->key); // raise gc counter by one, so it will be 2

0 commit comments

Comments
 (0)