Skip to content

Commit

Permalink
Use faster API for adding element to packed array
Browse files Browse the repository at this point in the history
This API is supported since PHP 8.2
  • Loading branch information
JakubOnderka committed Nov 28, 2024
1 parent 3c9d2be commit 72c4692
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/simdjson_bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,18 +185,20 @@ static simdjson_php_error_code create_array(simdjson::dom::element element, zval
}

zend_array *arr = simdjson_init_packed_array(return_value, json_array.size());

#if PHP_VERSION_ID >= 80200
ZEND_HASH_FILL_PACKED(arr) {
for (simdjson::dom::element child : json_array) {
create_array(child, __fill_val);
ZEND_HASH_FILL_NEXT();
}
} ZEND_HASH_FILL_END();
#else
for (simdjson::dom::element child : json_array) {
zval array_element;
simdjson_php_error_code error = create_array(child, &array_element);
if (UNEXPECTED(error)) {
zval_ptr_dtor(return_value);
ZVAL_NULL(return_value);
return error;
}
zend_hash_next_index_insert(arr, &array_element);
zend_hash_next_index_insert_new(arr, &array_element);
}

#endif
break;
}
case simdjson::dom::element_type::OBJECT : {
Expand Down

0 comments on commit 72c4692

Please sign in to comment.