Skip to content

Commit c754be8

Browse files
committed
Apply same optimization for escape_quotes
1 parent 4e96b75 commit c754be8

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

ext/mysqlnd/mysqlnd_charset.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,12 @@ PHPAPI const MYSQLND_CHARSET * mysqlnd_find_charset_name(const char * const name
769769
}
770770
/* }}} */
771771

772+
static zend_always_inline bool mysqlnd_mb_validity_prerequisites_check(const MYSQLND_CHARSET * const cset, const zend_uchar *str)
773+
{
774+
/* Encodings that have a minimum length of 1 are compatible with ASCII.
775+
* So we can skip (for performance reasons) the check to mb_valid for them. */
776+
return cset->char_maxlen > 1 && (*str > 0x80 || cset->char_minlen > 1);
777+
}
772778

773779
/* {{{ mysqlnd_cset_escape_quotes */
774780
PHPAPI zend_ulong mysqlnd_cset_escape_quotes(const MYSQLND_CHARSET * const cset, char * newstr,
@@ -784,7 +790,7 @@ PHPAPI zend_ulong mysqlnd_cset_escape_quotes(const MYSQLND_CHARSET * const cset,
784790
unsigned int len = 0;
785791
/* check unicode characters */
786792

787-
if (cset->char_maxlen > 1 && (len = cset->mb_valid(escapestr, end))) {
793+
if (mysqlnd_mb_validity_prerequisites_check(cset, (const zend_uchar *) escapestr) && (len = cset->mb_valid(escapestr, end))) {
788794
ZEND_ASSERT(newstr + len <= newstr_e);
789795
/* copy mb char without escaping it */
790796
while (len--) {
@@ -823,10 +829,8 @@ PHPAPI zend_ulong mysqlnd_cset_escape_slashes(const MYSQLND_CHARSET * const cset
823829
for (;escapestr < end; escapestr++) {
824830
char esc = '\0';
825831

826-
/* check unicode characters
827-
* Encodings that have a minimum length of 1 are compatible with ASCII.
828-
* So we can skip (for performance reasons) the check to mb_valid for them. */
829-
if (cset->char_maxlen > 1 && (*((zend_uchar *) escapestr) > 0x80 || cset->char_minlen > 1)) {
832+
/* check unicode characters */
833+
if (mysqlnd_mb_validity_prerequisites_check(cset, (const zend_uchar *) escapestr)) {
830834
unsigned int len = cset->mb_valid(escapestr, end);
831835
if (len) {
832836
ZEND_ASSERT(newstr + len <= newstr_e);

0 commit comments

Comments
 (0)