@@ -61,27 +61,9 @@ static PHP_MINFO_FUNCTION(ctype)
61
61
}
62
62
/* }}} */
63
63
64
- static void ctype_impl (
65
- INTERNAL_FUNCTION_PARAMETERS , int (* iswhat )(int ), bool allow_digits , bool allow_minus ) {
66
- zval * c ;
67
-
68
- ZEND_PARSE_PARAMETERS_START (1 , 1 );
69
- Z_PARAM_ZVAL (c )
70
- ZEND_PARSE_PARAMETERS_END ();
71
-
72
- if (Z_TYPE_P (c ) == IS_STRING ) {
73
- char * p = Z_STRVAL_P (c ), * e = Z_STRVAL_P (c ) + Z_STRLEN_P (c );
74
- if (e == p ) {
75
- RETURN_FALSE ;
76
- }
77
- while (p < e ) {
78
- if (!iswhat ((int )* (unsigned char * )(p ++ ))) {
79
- RETURN_FALSE ;
80
- }
81
- }
82
- RETURN_TRUE ;
83
- }
84
-
64
+ /* Slow fallback for deprecated cases defined in a no-inline function to not bloat code. */
65
+ static zend_never_inline void ctype_fallback (zval * c , zval * return_value , int (* iswhat )(int ), bool allow_digits , bool allow_minus )
66
+ {
85
67
php_error_docref (NULL , E_DEPRECATED ,
86
68
"Argument of type %s will be interpreted as string in the future" , zend_zval_type_name (c ));
87
69
if (Z_TYPE_P (c ) == IS_LONG ) {
@@ -99,80 +81,105 @@ static void ctype_impl(
99
81
}
100
82
}
101
83
84
+ /* Define as a macro such that iswhat can use the macro version instead of the function version.
85
+ * This heavily reduces the overhead. (GH-11997) */
86
+ #define ctype_impl (iswhat , allow_digits , allow_minus ) do { \
87
+ zval *c; \
88
+ \
89
+ ZEND_PARSE_PARAMETERS_START(1, 1); \
90
+ Z_PARAM_ZVAL(c) \
91
+ ZEND_PARSE_PARAMETERS_END(); \
92
+ \
93
+ if (Z_TYPE_P(c) == IS_STRING) { \
94
+ char *p = Z_STRVAL_P(c), *e = Z_STRVAL_P(c) + Z_STRLEN_P(c); \
95
+ if (e == p) { \
96
+ RETURN_FALSE; \
97
+ } \
98
+ while (p < e) { \
99
+ if (!iswhat((int)*(unsigned char *)(p++))) { \
100
+ RETURN_FALSE; \
101
+ } \
102
+ } \
103
+ RETURN_TRUE; \
104
+ } \
105
+ \
106
+ ctype_fallback(c, return_value, iswhat, allow_digits, allow_minus); \
107
+ } while (0);
108
+
102
109
/* {{{ Checks for alphanumeric character(s) */
103
110
PHP_FUNCTION (ctype_alnum )
104
111
{
105
- ctype_impl (INTERNAL_FUNCTION_PARAM_PASSTHRU , isalnum , 1 , 0 );
112
+ ctype_impl (isalnum , 1 , 0 );
106
113
}
107
114
/* }}} */
108
115
109
116
/* {{{ Checks for alphabetic character(s) */
110
117
PHP_FUNCTION (ctype_alpha )
111
118
{
112
- ctype_impl (INTERNAL_FUNCTION_PARAM_PASSTHRU , isalpha , 0 , 0 );
119
+ ctype_impl (isalpha , 0 , 0 );
113
120
}
114
121
/* }}} */
115
122
116
123
/* {{{ Checks for control character(s) */
117
124
PHP_FUNCTION (ctype_cntrl )
118
125
{
119
- ctype_impl (INTERNAL_FUNCTION_PARAM_PASSTHRU , iscntrl , 0 , 0 );
126
+ ctype_impl (iscntrl , 0 , 0 );
120
127
}
121
128
/* }}} */
122
129
123
130
/* {{{ Checks for numeric character(s) */
124
131
PHP_FUNCTION (ctype_digit )
125
132
{
126
- ctype_impl (INTERNAL_FUNCTION_PARAM_PASSTHRU , isdigit , 1 , 0 );
133
+ ctype_impl (isdigit , 1 , 0 );
127
134
}
128
135
/* }}} */
129
136
130
137
/* {{{ Checks for lowercase character(s) */
131
138
PHP_FUNCTION (ctype_lower )
132
139
{
133
- ctype_impl (INTERNAL_FUNCTION_PARAM_PASSTHRU , islower , 0 , 0 );
140
+ ctype_impl (islower , 0 , 0 );
134
141
}
135
142
/* }}} */
136
143
137
144
/* {{{ Checks for any printable character(s) except space */
138
145
PHP_FUNCTION (ctype_graph )
139
146
{
140
- ctype_impl (INTERNAL_FUNCTION_PARAM_PASSTHRU , isgraph , 1 , 1 );
147
+ ctype_impl (isgraph , 1 , 1 );
141
148
}
142
149
/* }}} */
143
150
144
151
/* {{{ Checks for printable character(s) */
145
152
PHP_FUNCTION (ctype_print )
146
153
{
147
- ctype_impl (INTERNAL_FUNCTION_PARAM_PASSTHRU , isprint , 1 , 1 );
154
+ ctype_impl (isprint , 1 , 1 );
148
155
}
149
156
/* }}} */
150
157
151
158
/* {{{ Checks for any printable character which is not whitespace or an alphanumeric character */
152
159
PHP_FUNCTION (ctype_punct )
153
160
{
154
- ctype_impl (INTERNAL_FUNCTION_PARAM_PASSTHRU , ispunct , 0 , 0 );
161
+ ctype_impl (ispunct , 0 , 0 );
155
162
}
156
163
/* }}} */
157
164
158
165
/* {{{ Checks for whitespace character(s)*/
159
166
PHP_FUNCTION (ctype_space )
160
167
{
161
- ctype_impl (INTERNAL_FUNCTION_PARAM_PASSTHRU , isspace , 0 , 0 );
168
+ ctype_impl (isspace , 0 , 0 );
162
169
}
163
170
/* }}} */
164
171
165
172
/* {{{ Checks for uppercase character(s) */
166
173
PHP_FUNCTION (ctype_upper )
167
174
{
168
- ctype_impl (INTERNAL_FUNCTION_PARAM_PASSTHRU , isupper , 0 , 0 );
175
+ ctype_impl (isupper , 0 , 0 );
169
176
}
170
177
/* }}} */
171
178
172
179
/* {{{ Checks for character(s) representing a hexadecimal digit */
173
180
PHP_FUNCTION (ctype_xdigit )
174
181
{
175
- ctype_impl (INTERNAL_FUNCTION_PARAM_PASSTHRU , isxdigit , 1 , 0 );
182
+ ctype_impl (isxdigit , 1 , 0 );
176
183
}
177
184
/* }}} */
178
185
0 commit comments