@@ -192,7 +192,7 @@ static zend_always_inline void simdjson_set_zval_to_string(zval *v, const char *
192
192
193
193
#if PHP_VERSION_ID >= 80200
194
194
// Copy of PHP method zend_hash_str_find_bucket that is not exported without checking if p->key is not null
195
- static zend_always_inline Bucket *simdjson_zend_hash_str_find_bucket (const HashTable *ht, const char *str, size_t len, zend_ulong h) {
195
+ static zend_always_inline Bucket *simdjson_hash_str_find_bucket (const HashTable *ht, const char *str, size_t len, zend_ulong h) {
196
196
uint32_t nIndex;
197
197
uint32_t idx;
198
198
Bucket *p, *arData;
@@ -229,12 +229,13 @@ static zend_always_inline void simdjson_init_reused_key_strings(HashTable *ht) {
229
229
ht->nNumUsed = 0 ;
230
230
ht->nTableSize = SIMDJSON_DEDUP_STRING_COUNT;
231
231
// zend_hash_real_init_mixed
232
- void * data = emalloc (HT_SIZE_EX (SIMDJSON_DEDUP_STRING_COUNT, HT_SIZE_TO_MASK (SIMDJSON_DEDUP_STRING_COUNT)));
232
+ void *data = emalloc (HT_SIZE_EX (SIMDJSON_DEDUP_STRING_COUNT, HT_SIZE_TO_MASK (SIMDJSON_DEDUP_STRING_COUNT)));
233
233
ht->nTableMask = HT_SIZE_TO_MASK (SIMDJSON_DEDUP_STRING_COUNT);
234
234
HT_SET_DATA_ADDR (ht, data);
235
235
HT_HASH_RESET (ht);
236
236
} else if (ht->nNumUsed > SIMDJSON_DEDUP_STRING_COUNT / 2 ) {
237
- // more than half of hash table is already full, cleanup
237
+ // more than half of hash table is already full before decoding new structure, so we will make space for new keys
238
+ // by removing old keys
238
239
simdjson_release_reused_key_strings (ht);
239
240
ZEND_ASSERT (ht->nTableMask == HT_SIZE_TO_MASK (SIMDJSON_DEDUP_STRING_COUNT));
240
241
HT_HASH_RESET (ht);
@@ -253,15 +254,15 @@ static zend_always_inline zend_string* simdjson_dedup_key(HashTable *ht, const c
253
254
Bucket *p;
254
255
zend_string *key;
255
256
256
- if (len > SIMDJSON_MAX_DEDUP_LENGTH) {
257
+ if (UNEXPECTED ( len > SIMDJSON_MAX_DEDUP_LENGTH) ) {
257
258
goto init_new_string;
258
259
}
259
260
260
261
// This should make computation faster, as we know array size
261
262
ZEND_ASSERT (ht != NULL );
262
263
ZEND_ASSERT (ht->nTableMask == HT_SIZE_TO_MASK (SIMDJSON_DEDUP_STRING_COUNT));
263
264
264
- p = simdjson_zend_hash_str_find_bucket (ht, str, len, h);
265
+ p = simdjson_hash_str_find_bucket (ht, str, len, h);
265
266
if (p) { // Key already exists, reuse
266
267
GC_ADDREF (p->key ); // raise reference counter by one
267
268
return p->key ;
@@ -274,7 +275,7 @@ static zend_always_inline zend_string* simdjson_dedup_key(HashTable *ht, const c
274
275
idx = ht->nNumUsed ++;
275
276
p = ht->arData + idx;
276
277
p->key = simdjson_string_init (str, len); // initialize new string for key
277
- GC_ADDREF (p->key ); // raise gc counter by one, so it will be 2
278
+ GC_SET_REFCOUNT (p->key , 2 );
278
279
p->h = ZSTR_H (p->key ) = h;
279
280
// ZVAL_NULL(&p->val); // we dont need set value to null, as we don't use it and destructor is set to NULL
280
281
nIndex = h | ht->nTableMask ;
@@ -291,7 +292,7 @@ static zend_always_inline zend_string* simdjson_dedup_key(HashTable *ht, const c
291
292
* - initialized array as zend_hash_real_init_mixed
292
293
* - exact size must be known in advance
293
294
*/
294
- static zend_always_inline void simdjson_zend_hash_str_add_or_update (HashTable *ht, const char *str, size_t len, zval *pData, HashTable *dedup_key_strings) {
295
+ static zend_always_inline void simdjson_hash_str_add_or_update (HashTable *ht, const char *str, size_t len, zval *pData, HashTable *dedup_key_strings) {
295
296
uint32_t nIndex;
296
297
uint32_t idx;
297
298
Bucket *p;
@@ -306,7 +307,7 @@ static zend_always_inline void simdjson_zend_hash_str_add_or_update(HashTable *h
306
307
// Compute key hash
307
308
h = zend_inline_hash_func (str, len);
308
309
309
- p = simdjson_zend_hash_str_find_bucket (ht, str, len, h);
310
+ p = simdjson_hash_str_find_bucket (ht, str, len, h);
310
311
if (UNEXPECTED (p)) { // Key already exists, replace value
311
312
zval *data;
312
313
ZEND_ASSERT (&p->val != pData);
@@ -318,8 +319,7 @@ static zend_always_inline void simdjson_zend_hash_str_add_or_update(HashTable *h
318
319
ht->nNumOfElements ++;
319
320
p = ht->arData + idx;
320
321
p->key = simdjson_dedup_key (dedup_key_strings, str, len, h); // initialize new string for key
321
- // p->key = simdjson_string_init(str, len);
322
- p->h = /* ZSTR_H(p->key) =*/ h;
322
+ p->h = h;
323
323
HT_FLAGS (ht) &= ~HASH_FLAG_STATIC_KEYS;
324
324
ZVAL_COPY_VALUE (&p->val , pData);
325
325
nIndex = h | ht->nTableMask ;
@@ -333,13 +333,14 @@ static zend_always_inline void simdjson_add_key_to_symtable(HashTable *ht, const
333
333
#if PHP_VERSION_ID >= 80200
334
334
zend_ulong idx;
335
335
if (UNEXPECTED (ZEND_HANDLE_NUMERIC_STR (buf, len, idx))) {
336
- zend_hash_index_update (ht, idx, value); // if index is inter in string format, use integer as index
336
+ // if index is inter in string format, use integer as index
337
+ zend_hash_index_update (ht, idx, value);
337
338
} else if (UNEXPECTED (len <= 1 )) {
338
339
// Use interned string
339
340
zend_string *key = len == 1 ? ZSTR_CHAR ((unsigned char )buf[0 ]) : ZSTR_EMPTY_ALLOC ();
340
341
zend_hash_update (ht, key, value);
341
342
} else {
342
- simdjson_zend_hash_str_add_or_update (ht, buf, len, value, dedup_key_strings);
343
+ simdjson_hash_str_add_or_update (ht, buf, len, value, dedup_key_strings);
343
344
}
344
345
#else
345
346
if (len <= 1 ) {
0 commit comments