[php-src] master: ext/standard: Make `str_ends_with` frameless (#23510)
Weilin Du via GitHub <[email protected]>
| Newsgroups | gmane.comp.php.cvs.general |
|---|---|
| Message-ID | <[email protected]> |
Author: Weilin Du (LamentXU123)
Committer: GitHub (web-flow)
Pusher: LamentXU123
Date: 2026-08-31T00:19:57+08:00
Commit: https://github.com/php/php-src/commit/027a5f8536468498a659684cf273d4f8bdd06706
Raw diff: https://github.com/php/php-src/commit/027a5f8536468498a659684cf273d4f8bdd06706.diff
ext/standard: Make `str_ends_with` frameless (#23510)
Since str_starts_with is frameless, str_ends_with also
should be frameless.
Changed paths:
M UPGRADING
M ext/standard/basic_functions.stub.php
M ext/standard/basic_functions_arginfo.h
M ext/standard/basic_functions_decl.h
M ext/standard/string.c
Diff:
diff --git a/UPGRADING b/UPGRADING
index a164599c6f15..5a5cafc0234f 100644
--- a/UPGRADING
+++ b/UPGRADING
@@ -973,6 +973,7 @@ PHP 8.6 UPGRADE NOTES
. Reduced temporary allocations when iterating Phar directories.
- Standard:
+ . Improved performance of str_ends_with().
. Improved performance of array_fill_keys().
. Improved performance of array_intersect().
. Improved performance of array_map() with multiple arrays passed.
diff --git a/ext/standard/basic_functions.stub.php b/ext/standard/basic_functions.stub.php
index 3e23934cbc78..8ae94d8c6d99 100644
--- a/ext/standard/basic_functions.stub.php
+++ b/ext/standard/basic_functions.stub.php
@@ -2451,7 +2451,10 @@ function str_contains(string $haystack, string $needle): bool {}
*/
function str_starts_with(string $haystack, string $needle): bool {}
-/** @compile-time-eval */
+/**
+ * @compile-time-eval
+ * @frameless-function {"arity": 2}
+ */
function str_ends_with(string $haystack, string $needle): bool {}
/**
diff --git a/ext/standard/basic_functions_arginfo.h b/ext/standard/basic_functions_arginfo.h
index 442085e9d6cc..4bcf008f5fdd 100644
--- a/ext/standard/basic_functions_arginfo.h
+++ b/ext/standard/basic_functions_arginfo.h
@@ -1,5 +1,5 @@
/* This is a generated file, edit basic_functions.stub.php instead.
- * Stub hash: c645e310c00d9f4cb3856c94ee60d06071e28de0
+ * Stub hash: 31018a787ba261316941b0d88f090b9cf271aa0e
* Has decl header: yes */
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_set_time_limit, 0, 1, _IS_BOOL, 0)
@@ -2294,6 +2294,12 @@ static const zend_frameless_function_info frameless_function_infos_str_starts_wi
{ 0 },
};
+ZEND_FRAMELESS_FUNCTION(str_ends_with, 2);
+static const zend_frameless_function_info frameless_function_infos_str_ends_with[] = {
+ { ZEND_FRAMELESS_FUNCTION_NAME(str_ends_with, 2), 2 },
+ { 0 },
+};
+
ZEND_FRAMELESS_FUNCTION(substr, 2);
ZEND_FRAMELESS_FUNCTION(substr, 3);
static const zend_frameless_function_info frameless_function_infos_substr[] = {
@@ -3197,7 +3203,7 @@ static const zend_function_entry ext_functions[] = {
ZEND_RAW_FENTRY("strrchr", zif_strrchr, arginfo_strrchr, ZEND_ACC_COMPILE_TIME_EVAL, NULL, NULL)
ZEND_RAW_FENTRY("str_contains", zif_str_contains, arginfo_str_contains, ZEND_ACC_COMPILE_TIME_EVAL, frameless_function_infos_str_contains, NULL)
ZEND_RAW_FENTRY("str_starts_with", zif_str_starts_with, arginfo_str_starts_with, ZEND_ACC_COMPILE_TIME_EVAL, frameless_function_infos_str_starts_with, NULL)
- ZEND_RAW_FENTRY("str_ends_with", zif_str_ends_with, arginfo_str_ends_with, ZEND_ACC_COMPILE_TIME_EVAL, NULL, NULL)
+ ZEND_RAW_FENTRY("str_ends_with", zif_str_ends_with, arginfo_str_ends_with, ZEND_ACC_COMPILE_TIME_EVAL, frameless_function_infos_str_ends_with, NULL)
ZEND_RAW_FENTRY("chunk_split", zif_chunk_split, arginfo_chunk_split, ZEND_ACC_COMPILE_TIME_EVAL, NULL, NULL)
ZEND_RAW_FENTRY("substr", zif_substr, arginfo_substr, ZEND_ACC_COMPILE_TIME_EVAL, frameless_function_infos_substr, NULL)
ZEND_RAW_FENTRY("substr_replace", zif_substr_replace, arginfo_substr_replace, ZEND_ACC_COMPILE_TIME_EVAL, NULL, NULL)
diff --git a/ext/standard/basic_functions_decl.h b/ext/standard/basic_functions_decl.h
index f2f234f60cc2..db81e0bfc077 100644
--- a/ext/standard/basic_functions_decl.h
+++ b/ext/standard/basic_functions_decl.h
@@ -1,8 +1,8 @@
/* This is a generated file, edit basic_functions.stub.php instead.
- * Stub hash: c645e310c00d9f4cb3856c94ee60d06071e28de0 */
+ * Stub hash: 31018a787ba261316941b0d88f090b9cf271aa0e */
-#ifndef ZEND_BASIC_FUNCTIONS_DECL_c645e310c00d9f4cb3856c94ee60d06071e28de0_H
-#define ZEND_BASIC_FUNCTIONS_DECL_c645e310c00d9f4cb3856c94ee60d06071e28de0_H
+#ifndef ZEND_BASIC_FUNCTIONS_DECL_31018a787ba261316941b0d88f090b9cf271aa0e_H
+#define ZEND_BASIC_FUNCTIONS_DECL_31018a787ba261316941b0d88f090b9cf271aa0e_H
typedef enum zend_enum_SortDirection {
ZEND_ENUM_SortDirection_Ascending = 1,
@@ -20,4 +20,4 @@ typedef enum zend_enum_RoundingMode {
ZEND_ENUM_RoundingMode_PositiveInfinity = 8,
} zend_enum_RoundingMode;
-#endif /* ZEND_BASIC_FUNCTIONS_DECL_c645e310c00d9f4cb3856c94ee60d06071e28de0_H */
+#endif /* ZEND_BASIC_FUNCTIONS_DECL_31018a787ba261316941b0d88f090b9cf271aa0e_H */
diff --git a/ext/standard/string.c b/ext/standard/string.c
index e5307a4f2d4b..af3f6a461dcf 100644
--- a/ext/standard/string.c
+++ b/ext/standard/string.c
@@ -1895,6 +1895,21 @@ PHP_FUNCTION(str_ends_with)
}
/* }}} */
+ZEND_FRAMELESS_FUNCTION(str_ends_with, 2)
+{
+ zval haystack_tmp, needle_tmp;
+ zend_string *haystack, *needle;
+
+ Z_FLF_PARAM_STR(1, haystack, haystack_tmp);
+ Z_FLF_PARAM_STR(2, needle, needle_tmp);
+
+ RETVAL_BOOL(zend_string_ends_with(haystack, needle));
+
+flf_clean:
+ Z_FLF_PARAM_FREE_STR(1, haystack_tmp);
+ Z_FLF_PARAM_FREE_STR(2, needle_tmp);
+}
+
static zend_always_inline void _zend_strpos(zval *return_value, zend_string *haystack, zend_string *needle, zend_long offset)
{
const char *found = NULL;