[php-src] master: ext/standard: Avoid redundant hash checks in getopt()

From: Date: Thu, 17 Sep 2026 01:38:25 +0000
Subject: [php-src] master: ext/standard: Avoid redundant hash checks in getopt()
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-141245@lists.php.net to get a copy of this message
Author: Weilin Du (LamentXU123) Date: 2026-09-17T09:38:17+08:00 Commit: https://github.com/php/php-src/commit/f0ed2c5890cc0c955c7a4ef99ba77ecd69584459 Raw diff: https://github.com/php/php-src/commit/f0ed2c5890cc0c955c7a4ef99ba77ecd69584459.diff ext/standard: Avoid redundant hash checks in getopt() Repeated option values accumulate in private arrays that are only appended to. New option keys are inserted after a failed lookup. Use known-new insertion helpers for both cases. Changed paths: M ext/standard/basic_functions.c Diff: diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 3438d6037526..1e00661cac2c 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -1078,9 +1078,9 @@ PHP_FUNCTION(getopt) if (Z_TYPE_P(args) != IS_ARRAY) { convert_to_array(args); } - zend_hash_next_index_insert(Z_ARRVAL_P(args), &val); + zend_hash_next_index_insert_new(Z_ARRVAL_P(args), &val); } else { - zend_hash_index_update(Z_ARRVAL_P(return_value), opt_name_as_long, &val); + zend_hash_index_add_new(Z_ARRVAL_P(return_value), opt_name_as_long, &val); } } else { /* other strings */ @@ -1088,9 +1088,9 @@ PHP_FUNCTION(getopt) if (Z_TYPE_P(args) != IS_ARRAY) { convert_to_array(args); } - zend_hash_next_index_insert(Z_ARRVAL_P(args), &val); + zend_hash_next_index_insert_new(Z_ARRVAL_P(args), &val); } else { - zend_hash_str_add(Z_ARRVAL_P(return_value), optname, optname_len, &val); + zend_hash_str_add_new(Z_ARRVAL_P(return_value), optname, optname_len, &val); } }

« previous php.cvs (#141245) next »