Skip to content

Commit cd408f1

Browse files
committed
MFH: minor speedup - convert offset to long only when needed
1 parent bdc0acd commit cd408f1

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

ext/spl/spl_fixedarray.c

+20-4
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,11 @@ static inline zval **spl_fixedarray_object_read_dimension_helper(spl_fixedarray_
317317
return NULL;
318318
}
319319

320-
index = spl_offset_convert_to_long(offset TSRMLS_CC);
320+
if (Z_TYPE_P(offset) != IS_LONG) {
321+
index = spl_offset_convert_to_long(offset TSRMLS_CC);
322+
} else {
323+
index = Z_LVAL_P(offset);
324+
}
321325

322326
if (index < 0 || intern->array == NULL || index >= intern->array->size) {
323327
zend_throw_exception(spl_ce_RuntimeException, "Index invalid or out of range", 0 TSRMLS_CC);
@@ -369,7 +373,11 @@ static inline void spl_fixedarray_object_write_dimension_helper(spl_fixedarray_o
369373
return;
370374
}
371375

372-
index = spl_offset_convert_to_long(offset TSRMLS_CC);
376+
if (Z_TYPE_P(offset) != IS_LONG) {
377+
index = spl_offset_convert_to_long(offset TSRMLS_CC);
378+
} else {
379+
index = Z_LVAL_P(offset);
380+
}
373381

374382
if (index < 0 || intern->array == NULL || index >= intern->array->size) {
375383
zend_throw_exception(spl_ce_RuntimeException, "Index invalid or out of range", 0 TSRMLS_CC);
@@ -407,7 +415,11 @@ static inline void spl_fixedarray_object_unset_dimension_helper(spl_fixedarray_o
407415
{
408416
long index;
409417

410-
index = spl_offset_convert_to_long(offset TSRMLS_CC);
418+
if (Z_TYPE_P(offset) != IS_LONG) {
419+
index = spl_offset_convert_to_long(offset TSRMLS_CC);
420+
} else {
421+
index = Z_LVAL_P(offset);
422+
}
411423

412424
if (index < 0 || intern->array == NULL || index >= intern->array->size) {
413425
zend_throw_exception(spl_ce_RuntimeException, "Index invalid or out of range", 0 TSRMLS_CC);
@@ -444,7 +456,11 @@ static inline int spl_fixedarray_object_has_dimension_helper(spl_fixedarray_obje
444456
long index;
445457
int retval;
446458

447-
index = spl_offset_convert_to_long(offset TSRMLS_CC);
459+
if (Z_TYPE_P(offset) != IS_LONG) {
460+
index = spl_offset_convert_to_long(offset TSRMLS_CC);
461+
} else {
462+
index = Z_LVAL_P(offset);
463+
}
448464

449465
if (index < 0 || intern->array == NULL || index >= intern->array->size) {
450466
retval = 0;

0 commit comments

Comments
 (0)