Skip to content

Commit 2edf94a

Browse files
committed
Avoid useless copying and conversion
1 parent 7eb045d commit 2edf94a

File tree

1 file changed

+19
-22
lines changed

1 file changed

+19
-22
lines changed

ext/ctype/ctype.c

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ static PHP_MINFO_FUNCTION(ctype)
142142

143143
/* {{{ ctype
144144
*/
145-
#define CTYPE(iswhat) \
146-
zval *c, tmp; \
145+
#define CTYPE(iswhat, allow_digits, allow_minus) \
146+
zval *c; \
147147
ZEND_PARSE_PARAMETERS_START(1, 1); \
148148
Z_PARAM_ZVAL(c) \
149149
ZEND_PARSE_PARAMETERS_END(); \
@@ -152,24 +152,21 @@ static PHP_MINFO_FUNCTION(ctype)
152152
RETURN_BOOL(iswhat((int)Z_LVAL_P(c))); \
153153
} else if (Z_LVAL_P(c) >= -128 && Z_LVAL_P(c) < 0) { \
154154
RETURN_BOOL(iswhat((int)Z_LVAL_P(c) + 256)); \
155+
} else if (Z_LVAL_P(c) >= 0) { \
156+
RETURN_BOOL(allow_digits); \
157+
} else { \
158+
RETURN_BOOL(allow_minus); \
155159
} \
156-
ZVAL_STR(&tmp, zval_get_string_func(c)); \
157-
} else { \
158-
ZVAL_COPY_VALUE(&tmp, c); \
159-
} \
160-
if (Z_TYPE(tmp) == IS_STRING) { \
161-
char *p = Z_STRVAL(tmp), *e = Z_STRVAL(tmp) + Z_STRLEN(tmp); \
160+
} else if (Z_TYPE_P(c) == IS_STRING) { \
161+
char *p = Z_STRVAL_P(c), *e = Z_STRVAL_P(c) + Z_STRLEN_P(c); \
162162
if (e == p) { \
163-
if (Z_TYPE_P(c) == IS_LONG) zval_dtor(&tmp); \
164163
RETURN_FALSE; \
165164
} \
166165
while (p < e) { \
167166
if(!iswhat((int)*(unsigned char *)(p++))) { \
168-
if (Z_TYPE_P(c) == IS_LONG) zval_dtor(&tmp); \
169167
RETURN_FALSE; \
170168
} \
171169
} \
172-
if (Z_TYPE_P(c) == IS_LONG) zval_dtor(&tmp); \
173170
RETURN_TRUE; \
174171
} else { \
175172
RETURN_FALSE; \
@@ -181,87 +178,87 @@ static PHP_MINFO_FUNCTION(ctype)
181178
Checks for alphanumeric character(s) */
182179
static PHP_FUNCTION(ctype_alnum)
183180
{
184-
CTYPE(isalnum);
181+
CTYPE(isalnum, 1, 0);
185182
}
186183
/* }}} */
187184

188185
/* {{{ proto bool ctype_alpha(mixed c)
189186
Checks for alphabetic character(s) */
190187
static PHP_FUNCTION(ctype_alpha)
191188
{
192-
CTYPE(isalpha);
189+
CTYPE(isalpha, 0, 0);
193190
}
194191
/* }}} */
195192

196193
/* {{{ proto bool ctype_cntrl(mixed c)
197194
Checks for control character(s) */
198195
static PHP_FUNCTION(ctype_cntrl)
199196
{
200-
CTYPE(iscntrl);
197+
CTYPE(iscntrl, 0, 0);
201198
}
202199
/* }}} */
203200

204201
/* {{{ proto bool ctype_digit(mixed c)
205202
Checks for numeric character(s) */
206203
static PHP_FUNCTION(ctype_digit)
207204
{
208-
CTYPE(isdigit);
205+
CTYPE(isdigit, 1, 0);
209206
}
210207
/* }}} */
211208

212209
/* {{{ proto bool ctype_lower(mixed c)
213210
Checks for lowercase character(s) */
214211
static PHP_FUNCTION(ctype_lower)
215212
{
216-
CTYPE(islower);
213+
CTYPE(islower, 0, 0);
217214
}
218215
/* }}} */
219216

220217
/* {{{ proto bool ctype_graph(mixed c)
221218
Checks for any printable character(s) except space */
222219
static PHP_FUNCTION(ctype_graph)
223220
{
224-
CTYPE(isgraph);
221+
CTYPE(isgraph, 1, 1);
225222
}
226223
/* }}} */
227224

228225
/* {{{ proto bool ctype_print(mixed c)
229226
Checks for printable character(s) */
230227
static PHP_FUNCTION(ctype_print)
231228
{
232-
CTYPE(isprint);
229+
CTYPE(isprint, 1, 1);
233230
}
234231
/* }}} */
235232

236233
/* {{{ proto bool ctype_punct(mixed c)
237234
Checks for any printable character which is not whitespace or an alphanumeric character */
238235
static PHP_FUNCTION(ctype_punct)
239236
{
240-
CTYPE(ispunct);
237+
CTYPE(ispunct, 0, 0);
241238
}
242239
/* }}} */
243240

244241
/* {{{ proto bool ctype_space(mixed c)
245242
Checks for whitespace character(s)*/
246243
static PHP_FUNCTION(ctype_space)
247244
{
248-
CTYPE(isspace);
245+
CTYPE(isspace, 0, 0);
249246
}
250247
/* }}} */
251248

252249
/* {{{ proto bool ctype_upper(mixed c)
253250
Checks for uppercase character(s) */
254251
static PHP_FUNCTION(ctype_upper)
255252
{
256-
CTYPE(isupper);
253+
CTYPE(isupper, 0, 0);
257254
}
258255
/* }}} */
259256

260257
/* {{{ proto bool ctype_xdigit(mixed c)
261258
Checks for character(s) representing a hexadecimal digit */
262259
static PHP_FUNCTION(ctype_xdigit)
263260
{
264-
CTYPE(isxdigit);
261+
CTYPE(isxdigit, 1, 0);
265262
}
266263
/* }}} */
267264

0 commit comments

Comments
 (0)