Skip to content

Conversation

TimWolla
Copy link
Member

Within an individual property handler, the parser is already implicitly known, which just leaves the ->uri field which must contain the entire state necessary for the handlers to work with.

Pass the ->uri directly. It avoids one pointer indirection, since the handlers do not need to follow the pointer to the uri_internal_t just to follow the pointer to the URI state. Instead the URI pointer can directly be passed using a register with the dereferences (if necessary) happening in the caller, providing more insight for the compiler to work with.

It also makes it more convenient to use the handlers directly for code that already knows that it needs a specific URI parser, since no uri_internal_t needs to be constructed to store the already-known information about which parser to use.

Within an individual property handler, the `parser` is already implicitly
known, which just leaves the `->uri` field which must contain the entire state
necessary for the handlers to work with.

Pass the `->uri` directly. It avoids one pointer indirection, since the
handlers do not need to follow the pointer to the `uri_internal_t` just to
follow the pointer to the URI state.  Instead the URI pointer can directly be
passed using a register with the dereferences (if necessary) happening in the
caller, providing more insight for the compiler to work with.

It also makes it more convenient to use the handlers directly for code that
already knows that it needs a specific URI parser, since no `uri_internal_t`
needs to be constructed to store the already-known information about which
parser to use.
This makes the code a little less verbose.
Comment on lines -68 to 99
zval tmp;
if (parser->property_handler.scheme.read(internal_uri, PHP_URI_COMPONENT_READ_MODE_RAW, &tmp) == SUCCESS) {
if (parser->property_handler.scheme.read(uri, PHP_URI_COMPONENT_READ_MODE_RAW, &tmp) == SUCCESS) {
zend_hash_update(result, ZSTR_KNOWN(ZEND_STR_SCHEME), &tmp);
}

if (parser->property_handler.username.read(internal_uri, PHP_URI_COMPONENT_READ_MODE_RAW, &tmp) == SUCCESS) {
if (parser->property_handler.username.read(uri, PHP_URI_COMPONENT_READ_MODE_RAW, &tmp) == SUCCESS) {
zend_hash_update(result, ZSTR_KNOWN(ZEND_STR_USERNAME), &tmp);
}

if (parser->property_handler.password.read(internal_uri, PHP_URI_COMPONENT_READ_MODE_RAW, &tmp) == SUCCESS) {
if (parser->property_handler.password.read(uri, PHP_URI_COMPONENT_READ_MODE_RAW, &tmp) == SUCCESS) {
zend_hash_update(result, ZSTR_KNOWN(ZEND_STR_PASSWORD), &tmp);
}

if (parser->property_handler.host.read(internal_uri, PHP_URI_COMPONENT_READ_MODE_RAW, &tmp) == SUCCESS) {
if (parser->property_handler.host.read(uri, PHP_URI_COMPONENT_READ_MODE_RAW, &tmp) == SUCCESS) {
zend_hash_update(result, ZSTR_KNOWN(ZEND_STR_HOST), &tmp);
}

if (parser->property_handler.port.read(internal_uri, PHP_URI_COMPONENT_READ_MODE_RAW, &tmp) == SUCCESS) {
if (parser->property_handler.port.read(uri, PHP_URI_COMPONENT_READ_MODE_RAW, &tmp) == SUCCESS) {
zend_hash_update(result, ZSTR_KNOWN(ZEND_STR_PORT), &tmp);
}

if (parser->property_handler.path.read(internal_uri, PHP_URI_COMPONENT_READ_MODE_RAW, &tmp) == SUCCESS) {
if (parser->property_handler.path.read(uri, PHP_URI_COMPONENT_READ_MODE_RAW, &tmp) == SUCCESS) {
zend_hash_update(result, ZSTR_KNOWN(ZEND_STR_PATH), &tmp);
}

if (parser->property_handler.query.read(internal_uri, PHP_URI_COMPONENT_READ_MODE_RAW, &tmp) == SUCCESS) {
if (parser->property_handler.query.read(uri, PHP_URI_COMPONENT_READ_MODE_RAW, &tmp) == SUCCESS) {
zend_hash_update(result, ZSTR_KNOWN(ZEND_STR_QUERY), &tmp);
}

if (parser->property_handler.fragment.read(internal_uri, PHP_URI_COMPONENT_READ_MODE_RAW, &tmp) == SUCCESS) {
if (parser->property_handler.fragment.read(uri, PHP_URI_COMPONENT_READ_MODE_RAW, &tmp) == SUCCESS) {
zend_hash_update(result, ZSTR_KNOWN(ZEND_STR_FRAGMENT), &tmp);
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this part of the diff shows nicely how much redundant work the handlers would have been doing when interested in multiple fields of an URI.

Copy link
Member

@kocsismate kocsismate left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice, thanks! Initially, I also passed the URI to these handlers, but later on, I bumped into some obstacles, and had to change for either a double pointer or an outer structure like the internal URI. I can't remember what the exact issue was though :( But apparently, it no longer exists

@TimWolla TimWolla merged commit 04deb4d into php:master Sep 11, 2025
9 checks passed
@TimWolla TimWolla deleted the uri-handler-no-uri-internal-t branch September 11, 2025 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants