Skip to content

Commit 7527cd6

Browse files
committed
stream: optimize filter seek method call
1 parent f6f6152 commit 7527cd6

File tree

1 file changed

+4
-18
lines changed

1 file changed

+4
-18
lines changed

ext/standard/user_filters.c

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -263,20 +263,17 @@ static zend_result userfilter_seek(
263263
)
264264
{
265265
zval *obj = &thisfilter->abstract;
266-
zval func_name;
267266
zval retval;
268267
zval args[2];
269-
int call_result;
270268

271269
/* the userfilter object probably doesn't exist anymore */
272270
if (CG(unclean_shutdown)) {
273271
return FAILURE;
274272
}
275273

276274
/* Check if the seek method exists */
277-
zend_string *method_name = ZSTR_INIT_LITERAL("seek", 0);
278-
if (!zend_hash_exists(&Z_OBJCE_P(obj)->function_table, method_name)) {
279-
zend_string_release(method_name);
275+
zend_function *seek_method = zend_hash_str_find_ptr(&Z_OBJCE_P(obj)->function_table, ZEND_STRL("seek"));
276+
if (seek_method == NULL) {
280277
/* Method doesn't exist - consider this a successful seek for BC */
281278
return SUCCESS;
282279
}
@@ -289,30 +286,19 @@ static zend_result userfilter_seek(
289286
if (userfilter_assign_stream(stream, obj, &stream_name) == FAILURE) {
290287
stream->flags &= ~PHP_STREAM_FLAG_NO_FCLOSE;
291288
stream->flags |= orig_no_fclose;
292-
zend_string_release(method_name);
293289
return FAILURE;
294290
}
295291

296-
ZVAL_STR(&func_name, method_name);
297-
298292
/* Setup calling arguments */
299293
ZVAL_LONG(&args[0], offset);
300294
ZVAL_LONG(&args[1], whence);
301295

302-
call_result = call_user_function(NULL,
303-
obj,
304-
&func_name,
305-
&retval,
306-
2, args);
307-
308-
zval_ptr_dtor(&func_name);
296+
zend_call_known_function(seek_method, Z_OBJ_P(obj), Z_OBJCE_P(obj), &retval, 2, args, NULL);
309297

310298
zend_result ret = FAILURE;
311-
if (call_result == SUCCESS && Z_TYPE(retval) != IS_UNDEF) {
299+
if (Z_TYPE(retval) != IS_UNDEF) {
312300
ret = zend_is_true(&retval) ? SUCCESS : FAILURE;
313301
zval_ptr_dtor(&retval);
314-
} else if (call_result == FAILURE) {
315-
php_error_docref(NULL, E_WARNING, "Failed to call seek function");
316302
}
317303

318304
/* filter resources are cleaned up by the stream destructor,

0 commit comments

Comments
 (0)