File tree Expand file tree Collapse file tree 1 file changed +3
-5
lines changed Expand file tree Collapse file tree 1 file changed +3
-5
lines changed Original file line number Diff line number Diff line change @@ -1887,7 +1887,7 @@ PHP_FUNCTION(str_starts_with) {
1887
1887
Checks if haystack ends with needle */
1888
1888
PHP_FUNCTION (str_ends_with ) {
1889
1889
zend_string * haystack , * needle ;
1890
- int i , j ;
1890
+ int k ;
1891
1891
1892
1892
ZEND_PARSE_PARAMETERS_START (2 , 2 )
1893
1893
Z_PARAM_STR (haystack )
@@ -1898,10 +1898,8 @@ PHP_FUNCTION(str_ends_with) {
1898
1898
RETURN_FALSE ;
1899
1899
}
1900
1900
1901
- for (i = haystack -> len - 1 , j = needle -> len - 1 ; j >= 0 ; i -- , j -- )
1902
- if (haystack -> val [i ] != needle -> val [j ])
1903
- RETURN_FALSE ;
1904
- RETURN_TRUE ;
1901
+ k = ZSTR_LEN (haystack ) - ZSTR_LEN (needle );
1902
+ RETURN_BOOL (memcmp (& (ZSTR_VAL (haystack ))[k ], & (ZSTR_VAL (needle ))[k ], ZSTR_LEN (needle )) == 0 );
1905
1903
}
1906
1904
1907
1905
/* {{{ proto string strchr(string haystack, string needle)
You can’t perform that action at this time.
0 commit comments