mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
Preallocate result array size in xpath (#12105)
We know what size they're going to be, and we know they are packed arrays. Prevent reallocations and initialisation overhead by setting the initial size and initializing it as packed from the start.
This commit is contained in:
parent
7be47953a3
commit
4dea42a3f8
1 changed files with 4 additions and 3 deletions
|
@ -95,7 +95,8 @@ static void dom_xpath_ext_function_php(xmlXPathParserContextPtr ctxt, int nargs,
|
||||||
} else if (type == 2) {
|
} else if (type == 2) {
|
||||||
int j;
|
int j;
|
||||||
if (obj->nodesetval && obj->nodesetval->nodeNr > 0) {
|
if (obj->nodesetval && obj->nodesetval->nodeNr > 0) {
|
||||||
array_init(&fci.params[i]);
|
array_init_size(&fci.params[i], obj->nodesetval->nodeNr);
|
||||||
|
zend_hash_real_init_packed(Z_ARRVAL_P(&fci.params[i]));
|
||||||
for (j = 0; j < obj->nodesetval->nodeNr; j++) {
|
for (j = 0; j < obj->nodesetval->nodeNr; j++) {
|
||||||
xmlNodePtr node = obj->nodesetval->nodeTab[j];
|
xmlNodePtr node = obj->nodesetval->nodeTab[j];
|
||||||
zval child;
|
zval child;
|
||||||
|
@ -408,8 +409,8 @@ static void php_xpath_eval(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */
|
||||||
xmlNodeSetPtr nodesetp;
|
xmlNodeSetPtr nodesetp;
|
||||||
|
|
||||||
if (xpathobjp->type == XPATH_NODESET && NULL != (nodesetp = xpathobjp->nodesetval) && nodesetp->nodeNr) {
|
if (xpathobjp->type == XPATH_NODESET && NULL != (nodesetp = xpathobjp->nodesetval) && nodesetp->nodeNr) {
|
||||||
|
array_init_size(&retval, nodesetp->nodeNr);
|
||||||
array_init(&retval);
|
zend_hash_real_init_packed(Z_ARRVAL_P(&retval));
|
||||||
for (i = 0; i < nodesetp->nodeNr; i++) {
|
for (i = 0; i < nodesetp->nodeNr; i++) {
|
||||||
xmlNodePtr node = nodesetp->nodeTab[i];
|
xmlNodePtr node = nodesetp->nodeTab[i];
|
||||||
zval child;
|
zval child;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue