Skip to content

Commit 6ac580c

Browse files
committed
Zend: avoid strlen() in zend_get_module_version()
1 parent a151551 commit 6ac580c

3 files changed

Lines changed: 10 additions & 4 deletions

File tree

Zend/zend_API.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4411,12 +4411,17 @@ ZEND_API void zend_get_callable_zval_from_fcc(const zend_fcall_info_cache *fcc,
44114411
}
44124412
}
44134413

4414-
ZEND_API const char *zend_get_module_version(const char *module_name) /* {{{ */
4414+
ZEND_API const char *zend_get_module_version_ex(const char *module_name, size_t module_name_len)
44154415
{
4416-
size_t name_len = strlen(module_name);
4417-
zend_module_entry *module = zend_hash_str_find_ptr_lc(&module_registry, module_name, name_len);
4416+
zend_module_entry *module = zend_hash_str_find_ptr_lc(&module_registry, module_name, module_name_len);
44184417
return module ? module->version : NULL;
44194418
}
4419+
4420+
ZEND_API const char *zend_get_module_version(const char *module_name) /* {{{ */
4421+
{
4422+
size_t name_len = strlen(module_name);
4423+
return zend_get_module_version_ex(module_name, name_len);
4424+
}
44204425
/* }}} */
44214426

44224427
static zend_always_inline bool is_persistent_class(const zend_class_entry *ce) {

Zend/zend_API.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ ZEND_API bool zend_is_callable_at_frame(
421421
ZEND_API bool zend_is_callable_ex(const zval *callable, zend_object *object, uint32_t check_flags, zend_string **callable_name, zend_fcall_info_cache *fcc, char **error);
422422
ZEND_API bool zend_is_callable(const zval *callable, uint32_t check_flags, zend_string **callable_name);
423423
ZEND_API const char *zend_get_module_version(const char *module_name);
424+
ZEND_API const char *zend_get_module_version_ex(const char *module_name, size_t module_name_name_len);
424425
ZEND_API zend_result zend_get_module_started(const char *module_name);
425426

426427
ZEND_API zend_property_info *zend_declare_typed_property(zend_class_entry *ce, zend_string *name, zval *property, int access_type, zend_string *doc_comment, zend_type type);

ext/standard/info.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1308,7 +1308,7 @@ PHP_FUNCTION(phpversion)
13081308
RETURN_STRING(PHP_VERSION);
13091309
} else {
13101310
const char *version;
1311-
version = zend_get_module_version(ext_name);
1311+
version = zend_get_module_version_ex(ext_name, ext_name_len);
13121312
if (version == NULL) {
13131313
RETURN_FALSE;
13141314
}

0 commit comments

Comments
 (0)