Skip to content

Commit e3d946a

Browse files
committed
Zend/zend_string: add zend_string_equals_str()
Allows eliminating duplicate code.
1 parent 2467c32 commit e3d946a

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

Zend/zend_string.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,8 @@ static zend_always_inline zend_string *zend_interned_string_ht_lookup_ex(zend_ul
135135
idx = HT_HASH(interned_strings, nIndex);
136136
while (idx != HT_INVALID_IDX) {
137137
p = HT_HASH_TO_BUCKET(interned_strings, idx);
138-
if ((p->h == h) && (ZSTR_LEN(p->key) == size)) {
139-
if (!memcmp(ZSTR_VAL(p->key), str, size)) {
140-
return p->key;
141-
}
138+
if ((p->h == h) && zend_string_equals_str(p->key, str, size)) {
139+
return p->key;
142140
}
143141
idx = Z_NEXT(p->val);
144142
}

Zend/zend_string.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,16 @@ static zend_always_inline void zend_string_release_ex(zend_string *s, bool persi
339339
}
340340
}
341341

342+
static zend_always_inline bool zend_string_equals_str(const zend_string *s1, const char *s2, size_t s2_length)
343+
{
344+
return ZSTR_LEN(s1) == s2_length && !memcmp(ZSTR_VAL(s1), s2, s2_length);
345+
}
346+
347+
static zend_always_inline bool zend_string_equals_cstr(const zend_string *s1, const char *s2)
348+
{
349+
return zend_string_equals_str(s1, s2, strlen(s2));
350+
}
351+
342352
#if defined(__GNUC__) && (defined(__i386__) || (defined(__x86_64__) && !defined(__ILP32__)))
343353
BEGIN_EXTERN_C()
344354
ZEND_API bool ZEND_FASTCALL zend_string_equal_val(zend_string *s1, zend_string *s2);
@@ -367,7 +377,7 @@ static zend_always_inline bool zend_string_equals(zend_string *s1, zend_string *
367377
(ZSTR_LEN(str) == sizeof(c) - 1 && !zend_binary_strcasecmp(ZSTR_VAL(str), ZSTR_LEN(str), (c), sizeof(c) - 1))
368378

369379
#define zend_string_equals_literal(str, literal) \
370-
(ZSTR_LEN(str) == sizeof(literal)-1 && !memcmp(ZSTR_VAL(str), literal, sizeof(literal) - 1))
380+
zend_string_equals_str(str, literal, sizeof(literal) - 1)
371381

372382
/*
373383
* DJBX33A (Daniel J. Bernstein, Times 33 with Addition)

0 commit comments

Comments
 (0)