@@ -377,10 +377,8 @@ ZEND_API uint32_t zend_array_count(HashTable *ht)
377
377
}
378
378
/* }}} */
379
379
380
- static zend_always_inline HashPosition _zend_hash_get_first_pos (const HashTable * ht )
380
+ static zend_always_inline HashPosition _zend_hash_get_valid_pos (const HashTable * ht , HashPosition pos )
381
381
{
382
- HashPosition pos = 0 ;
383
-
384
382
while (pos < ht -> nNumUsed && Z_ISUNDEF (ht -> arData [pos ].val )) {
385
383
pos ++ ;
386
384
}
@@ -389,12 +387,7 @@ static zend_always_inline HashPosition _zend_hash_get_first_pos(const HashTable
389
387
390
388
static zend_always_inline HashPosition _zend_hash_get_current_pos (const HashTable * ht )
391
389
{
392
- HashPosition pos = ht -> nInternalPointer ;
393
-
394
- if (pos == 0 ) {
395
- pos = _zend_hash_get_first_pos (ht );
396
- }
397
- return pos ;
390
+ return _zend_hash_get_valid_pos (ht , ht -> nInternalPointer );
398
391
}
399
392
400
393
ZEND_API HashPosition ZEND_FASTCALL zend_hash_get_current_pos (const HashTable * ht )
@@ -2189,7 +2182,7 @@ ZEND_API void ZEND_FASTCALL zend_hash_internal_pointer_reset_ex(HashTable *ht, H
2189
2182
{
2190
2183
IS_CONSISTENT (ht );
2191
2184
HT_ASSERT (ht , & ht -> nInternalPointer != pos || GC_REFCOUNT (ht ) == 1 );
2192
- * pos = _zend_hash_get_first_pos (ht );
2185
+ * pos = _zend_hash_get_valid_pos (ht , 0 );
2193
2186
}
2194
2187
2195
2188
@@ -2217,19 +2210,13 @@ ZEND_API void ZEND_FASTCALL zend_hash_internal_pointer_end_ex(HashTable *ht, Has
2217
2210
2218
2211
ZEND_API int ZEND_FASTCALL zend_hash_move_forward_ex (HashTable * ht , HashPosition * pos )
2219
2212
{
2220
- uint32_t idx = * pos ;
2213
+ uint32_t idx ;
2221
2214
2222
2215
IS_CONSISTENT (ht );
2223
2216
HT_ASSERT (ht , & ht -> nInternalPointer != pos || GC_REFCOUNT (ht ) == 1 );
2224
2217
2218
+ idx = _zend_hash_get_valid_pos (ht , * pos );
2225
2219
if (idx < ht -> nNumUsed ) {
2226
- if (idx == 0 ) {
2227
- idx = _zend_hash_get_first_pos (ht );
2228
- if (idx >= ht -> nNumUsed ) {
2229
- * pos = idx ;
2230
- return SUCCESS ;
2231
- }
2232
- }
2233
2220
while (1 ) {
2234
2221
idx ++ ;
2235
2222
if (idx >= ht -> nNumUsed ) {
@@ -2272,17 +2259,12 @@ ZEND_API int ZEND_FASTCALL zend_hash_move_backwards_ex(HashTable *ht, HashPositi
2272
2259
/* This function should be made binary safe */
2273
2260
ZEND_API int ZEND_FASTCALL zend_hash_get_current_key_ex (const HashTable * ht , zend_string * * str_index , zend_ulong * num_index , HashPosition * pos )
2274
2261
{
2275
- uint32_t idx = * pos ;
2262
+ uint32_t idx ;
2276
2263
Bucket * p ;
2277
2264
2278
2265
IS_CONSISTENT (ht );
2266
+ idx = _zend_hash_get_valid_pos (ht , * pos );
2279
2267
if (idx < ht -> nNumUsed ) {
2280
- if (idx == 0 ) {
2281
- idx = _zend_hash_get_first_pos (ht );
2282
- if (idx >= ht -> nNumUsed ) {
2283
- return HASH_KEY_NON_EXISTENT ;
2284
- }
2285
- }
2286
2268
p = ht -> arData + idx ;
2287
2269
if (p -> key ) {
2288
2270
* str_index = p -> key ;
@@ -2297,20 +2279,14 @@ ZEND_API int ZEND_FASTCALL zend_hash_get_current_key_ex(const HashTable *ht, zen
2297
2279
2298
2280
ZEND_API void ZEND_FASTCALL zend_hash_get_current_key_zval_ex (const HashTable * ht , zval * key , HashPosition * pos )
2299
2281
{
2300
- uint32_t idx = * pos ;
2282
+ uint32_t idx ;
2301
2283
Bucket * p ;
2302
2284
2303
2285
IS_CONSISTENT (ht );
2286
+ idx = _zend_hash_get_valid_pos (ht , * pos );
2304
2287
if (idx >= ht -> nNumUsed ) {
2305
2288
ZVAL_NULL (key );
2306
2289
} else {
2307
- if (idx == 0 ) {
2308
- idx = _zend_hash_get_first_pos (ht );
2309
- if (idx >= ht -> nNumUsed ) {
2310
- ZVAL_NULL (key );
2311
- return ;
2312
- }
2313
- }
2314
2290
p = ht -> arData + idx ;
2315
2291
if (p -> key ) {
2316
2292
ZVAL_STR_COPY (key , p -> key );
@@ -2322,17 +2298,12 @@ ZEND_API void ZEND_FASTCALL zend_hash_get_current_key_zval_ex(const HashTable *h
2322
2298
2323
2299
ZEND_API int ZEND_FASTCALL zend_hash_get_current_key_type_ex (HashTable * ht , HashPosition * pos )
2324
2300
{
2325
- uint32_t idx = * pos ;
2301
+ uint32_t idx ;
2326
2302
Bucket * p ;
2327
2303
2328
2304
IS_CONSISTENT (ht );
2305
+ idx = _zend_hash_get_valid_pos (ht , * pos );
2329
2306
if (idx < ht -> nNumUsed ) {
2330
- if (idx == 0 ) {
2331
- idx = _zend_hash_get_first_pos (ht );
2332
- if (idx >= ht -> nNumUsed ) {
2333
- return HASH_KEY_NON_EXISTENT ;
2334
- }
2335
- }
2336
2307
p = ht -> arData + idx ;
2337
2308
if (p -> key ) {
2338
2309
return HASH_KEY_IS_STRING ;
@@ -2346,17 +2317,12 @@ ZEND_API int ZEND_FASTCALL zend_hash_get_current_key_type_ex(HashTable *ht, Hash
2346
2317
2347
2318
ZEND_API zval * ZEND_FASTCALL zend_hash_get_current_data_ex (HashTable * ht , HashPosition * pos )
2348
2319
{
2349
- uint32_t idx = * pos ;
2320
+ uint32_t idx ;
2350
2321
Bucket * p ;
2351
2322
2352
2323
IS_CONSISTENT (ht );
2324
+ idx = _zend_hash_get_valid_pos (ht , * pos );
2353
2325
if (idx < ht -> nNumUsed ) {
2354
- if (idx == 0 ) {
2355
- idx = _zend_hash_get_first_pos (ht );
2356
- if (idx >= ht -> nNumUsed ) {
2357
- return NULL ;
2358
- }
2359
- }
2360
2326
p = ht -> arData + idx ;
2361
2327
return & p -> val ;
2362
2328
} else {
0 commit comments