Skip to content

Commit 1faaa72

Browse files
authored
uri: Remove useless layer of indirection in php_uri_get_parser() (#19774)
By using the `zend_hash_*()` functions directly, we can benefit from the precalculated hash value in the given `zend_string *uri_parser_name`. We need to deconstify the parameter, since the function might calculate the hash, thus modifying the `zend_string*`.
1 parent d2a54a0 commit 1faaa72

File tree

4 files changed

+6
-11
lines changed

4 files changed

+6
-11
lines changed

ext/soap/php_http.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ static bool in_domain(const zend_string *host, const zend_string *domain)
338338

339339
int make_http_soap_request(
340340
zval *this_ptr, zend_string *buf, zend_string *location, char *soapaction,
341-
int soap_version, const zend_string *uri_parser_class, zval *return_value
341+
int soap_version, zend_string *uri_parser_class, zval *return_value
342342
) {
343343
zend_string *request;
344344
smart_str soap_headers = {0};

ext/soap/php_http.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
int make_http_soap_request(
2323
zval *this_ptr, zend_string *buf, zend_string *location, char *soapaction,
24-
int soap_version, const zend_string *uri_parser_class, zval *return_value
24+
int soap_version, zend_string *uri_parser_class, zval *return_value
2525
);
2626

2727
int proxy_authentication(zval* this_ptr, smart_str* soap_headers);

ext/uri/php_uri.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,6 @@ static const zend_module_dep uri_deps[] = {
5050

5151
static zend_array uri_parsers;
5252

53-
static const uri_parser_t *uri_parser_by_name(const char *uri_parser_name, size_t uri_parser_name_len)
54-
{
55-
return zend_hash_str_find_ptr(&uri_parsers, uri_parser_name, uri_parser_name_len);
56-
}
57-
5853
static HashTable *uri_get_debug_properties(zend_object *object)
5954
{
6055
uri_internal_t *internal_uri = uri_internal_from_obj(object);
@@ -105,13 +100,13 @@ static HashTable *uri_get_debug_properties(zend_object *object)
105100
return result;
106101
}
107102

108-
PHPAPI const uri_parser_t *php_uri_get_parser(const zend_string *uri_parser_name)
103+
PHPAPI const uri_parser_t *php_uri_get_parser(zend_string *uri_parser_name)
109104
{
110105
if (uri_parser_name == NULL) {
111-
return uri_parser_by_name(PHP_URI_PARSER_PHP_PARSE_URL, sizeof(PHP_URI_PARSER_PHP_PARSE_URL) - 1);
106+
return zend_hash_str_find_ptr(&uri_parsers, PHP_URI_PARSER_PHP_PARSE_URL, sizeof(PHP_URI_PARSER_PHP_PARSE_URL) - 1);
112107
}
113108

114-
return uri_parser_by_name(ZSTR_VAL(uri_parser_name), ZSTR_LEN(uri_parser_name));
109+
return zend_hash_find_ptr(&uri_parsers, uri_parser_name);
115110
}
116111

117112
ZEND_ATTRIBUTE_NONNULL PHPAPI uri_internal_t *php_uri_parse(const uri_parser_t *uri_parser, const char *uri_str, size_t uri_str_len, bool silent)

ext/uri/php_uri.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ PHPAPI zend_result php_uri_parser_register(const uri_parser_t *uri_parser);
4747
* @param uri_parser_name The URI parser name
4848
* @return The URI parser
4949
*/
50-
PHPAPI const uri_parser_t *php_uri_get_parser(const zend_string *uri_parser_name);
50+
PHPAPI const uri_parser_t *php_uri_get_parser(zend_string *uri_parser_name);
5151

5252
ZEND_ATTRIBUTE_NONNULL PHPAPI uri_internal_t *php_uri_parse(const uri_parser_t *uri_parser, const char *uri_str, size_t uri_str_len, bool silent);
5353

0 commit comments

Comments
 (0)