Skip to content

Commit 0e6621a

Browse files
committed
zend_string: Add zend_string_equals_cstr_ci()
This function was missing for consistency with the other functions which all have a `cstr` variant. Adding this function also made it easy to convert some more copy-and-pasted logic.
1 parent 7c86d86 commit 0e6621a

3 files changed

Lines changed: 14 additions & 5 deletions

File tree

UPGRADING.INTERNALS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ PHP 8.6 INTERNALS UPGRADE NOTES
1717
. ZSTR_INIT_LITERAL(), zend_string_starts_with_literal(), and
1818
zend_string_starts_with_literal_ci() now support strings containing NUL
1919
bytes. Passing non-literal char* is no longer supported.
20+
. Added zend_string_equals_cstr_ci().
2021
. The misnamed ZVAL_IS_NULL() has been removed. Use Z_ISNULL() instead.
2122
. New zend_class_entry.ce_flags2 and zend_function.fn_flags2 fields were
2223
added, given the primary flags were running out of bits.

Zend/zend_operators.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
#include "zend_portability.h"
4747
#include "zend_strtod.h"
4848
#include "zend_multiply.h"
49-
#include "zend_object_handlers.h"
5049

5150
#define LONG_SIGN_MASK ZEND_LONG_MIN
5251

Zend/zend_string.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -397,11 +397,20 @@ static zend_always_inline bool zend_string_equals(const zend_string *s1, const z
397397
return s1 == s2 || zend_string_equal_content(s1, s2);
398398
}
399399

400-
#define zend_string_equals_ci(s1, s2) \
401-
(ZSTR_LEN(s1) == ZSTR_LEN(s2) && !zend_binary_strcasecmp(ZSTR_VAL(s1), ZSTR_LEN(s1), ZSTR_VAL(s2), ZSTR_LEN(s2)))
400+
ZEND_API int ZEND_FASTCALL zend_binary_strcasecmp(const char *s1, size_t len1, const char *s2, size_t len2);
402401

403-
#define zend_string_equals_literal_ci(str, c) \
404-
(ZSTR_LEN(str) == sizeof("" c) - 1 && !zend_binary_strcasecmp(ZSTR_VAL(str), ZSTR_LEN(str), (c), sizeof(c) - 1))
402+
static zend_always_inline bool zend_string_equals_cstr_ci(const zend_string *s1, const char *s2, size_t s2_length)
403+
{
404+
return ZSTR_LEN(s1) == s2_length && !zend_binary_strcasecmp(ZSTR_VAL(s1), ZSTR_LEN(s1), s2, s2_length);
405+
}
406+
407+
#define zend_string_equals_literal_ci(str, literal) \
408+
zend_string_equals_cstr_ci(str, "" literal, sizeof(literal) - 1)
409+
410+
static zend_always_inline bool zend_string_equals_ci(const zend_string *s1, const zend_string *s2)
411+
{
412+
return zend_string_equals_cstr_ci(s1, ZSTR_VAL(s2), ZSTR_LEN(s2));
413+
}
405414

406415
#define zend_string_equals_literal(str, literal) \
407416
zend_string_equals_cstr(str, "" literal, sizeof(literal) - 1)

0 commit comments

Comments
 (0)