Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,13 @@ PHP 8.6 UPGRADE NOTES
. Improved performance of indentation generation in json_encode()
when using PHP_JSON_PRETTY_PRINT.

- Intl:
. Improved performance of IntlCalendar::getAvailableLocales() and
IntlDateFormatter::localtime() / datefmt_localtime() by pre-allocating
their returned arrays.
. Improved performance of transliterator_list_ids() and
resourcebundle_locales() by pre-allocating their returned arrays.

- Phar:
. Reduced temporary allocations when iterating Phar directories.

Expand All @@ -514,10 +521,14 @@ PHP 8.6 UPGRADE NOTES
. Improved performance of str_split().

- URI:
. Improved performance of Uri\WhatWg\Url::parse() when collecting
validation errors by pre-allocating the error array.
. Reduced allocations when reading IPv6/IPFuture hosts and paths with
Uri\Rfc3986\Uri.
. Improved performance and memory consumption when using normalizing
(non-raw) getters on already-normalized URIs with Uri\Rfc3986\Uri.

- Zip:
. Improved performance of ZipArchive::addGlob() and
ZipArchive::addPattern() by pre-allocating their returned arrays.
. Avoid string copies in ZipArchive::addFromString().
33 changes: 33 additions & 0 deletions ext/dom/tests/xpath_php_function_removes_argument_node.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
--TEST--
DOMXPath: a php:function callback that removes its argument node must not free it mid-evaluation
--EXTENSIONS--
dom
--FILE--
<?php
$doc = new DOMDocument();
$doc->loadXML('<root><a>1</a><a>2</a><a>3</a><a>4</a></root>');
$xp = new DOMXPath($doc);
$xp->registerNamespace('php', 'http://php.net/xpath');
$xp->registerPhpFunctions();

function cb($nodes) {
foreach ($nodes as $n) {
if ($n->parentNode) {
$n->parentNode->removeChild($n);
}
}
return true;
}

$res = $xp->query('//a[php:function("cb", .)]');
foreach ($res as $r) {
var_dump($r->nodeName);
}
echo "done\n";
?>
--EXPECT--
string(1) "a"
string(1) "a"
string(1) "a"
string(1) "a"
done
16 changes: 12 additions & 4 deletions ext/dom/xpath_callbacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -379,11 +379,19 @@ static zval *php_dom_xpath_callback_fetch_args(xmlXPathParserContextPtr ctxt, ui
return params;
}

static void php_dom_xpath_callback_cleanup_args(zval *params, uint32_t param_count)
static void php_dom_xpath_callback_cleanup_args(php_dom_xpath_callbacks *xpath_callbacks, zval *params, uint32_t param_count)
{
if (params) {
for (uint32_t i = 0; i < param_count; i++) {
zval_ptr_dtor(&params[i]);
zval *param = &params[i];
if (Z_TYPE_P(param) == IS_OBJECT || Z_TYPE_P(param) == IS_ARRAY) {
if (xpath_callbacks->node_list == NULL) {
xpath_callbacks->node_list = zend_new_array(0);
}
zend_hash_next_index_insert_new(xpath_callbacks->node_list, param);
} else {
zval_ptr_dtor(param);
}
}
efree(params);
}
Expand Down Expand Up @@ -478,7 +486,7 @@ PHP_DOM_EXPORT zend_result php_dom_xpath_callbacks_call_php_ns(php_dom_xpath_cal

cleanup:
xmlXPathFreeObject(obj);
php_dom_xpath_callback_cleanup_args(params, param_count);
php_dom_xpath_callback_cleanup_args(xpath_callbacks, params, param_count);
cleanup_no_obj:
if (UNEXPECTED(result != SUCCESS)) {
/* Push sentinel value */
Expand Down Expand Up @@ -506,7 +514,7 @@ PHP_DOM_EXPORT zend_result php_dom_xpath_callbacks_call_custom_ns(php_dom_xpath_

zend_result result = php_dom_xpath_callback_dispatch(xpath_callbacks, ns, ctxt, params, param_count, function_name, function_name_length);

php_dom_xpath_callback_cleanup_args(params, param_count);
php_dom_xpath_callback_cleanup_args(xpath_callbacks, params, param_count);
if (UNEXPECTED(result != SUCCESS)) {
/* Push sentinel value */
valuePush(ctxt, xmlXPathNewString((const xmlChar *) ""));
Expand Down
9 changes: 8 additions & 1 deletion ext/intl/resourcebundle/resourcebundle_class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ U_CFUNC PHP_FUNCTION( resourcebundle_locales )
size_t bundlename_len = 0;
const char * entry;
int entry_len;
int32_t count;
UEnumeration *icuenum;
UErrorCode icuerror = U_ZERO_ERROR;

Expand All @@ -364,7 +365,13 @@ U_CFUNC PHP_FUNCTION( resourcebundle_locales )
uenum_reset( icuenum, &icuerror );
INTL_CHECK_STATUS(icuerror, "Cannot iterate locales list");

array_init( return_value );
count = uenum_count( icuenum, &icuerror );
if (U_FAILURE(icuerror)) {
count = 0;
icuerror = U_ZERO_ERROR;
}

array_init_size( return_value, count );
while ((entry = uenum_next( icuenum, &entry_len, &icuerror ))) {
add_next_index_stringl( return_value, (char *) entry, entry_len);
}
Expand Down
12 changes: 11 additions & 1 deletion ext/intl/transliterator/transliterator_methods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include <unicode/unistr.h>
#endif

#include <unicode/uenum.h>

extern "C" {
#include "php_intl.h"
#include "intl_data.h"
Expand Down Expand Up @@ -226,6 +228,7 @@ U_CFUNC PHP_FUNCTION( transliterator_list_ids )
UEnumeration *en;
const UChar *elem;
int32_t elem_len;
int32_t count;
UErrorCode status = U_ZERO_ERROR;

intl_error_reset( nullptr );
Expand All @@ -236,7 +239,14 @@ U_CFUNC PHP_FUNCTION( transliterator_list_ids )
INTL_CHECK_STATUS( status,
"Failed to obtain registered transliterators" );

array_init( return_value );
count = uenum_count( en, &status );
if( U_FAILURE( status ) )
{
count = 0;
status = U_ZERO_ERROR;
}

array_init_size( return_value, count );
while( (elem = uenum_unext( en, &elem_len, &status )) )
{
zend_string *el = intl_convert_utf16_to_utf8(elem, elem_len, &status );
Expand Down
Loading