-
Notifications
You must be signed in to change notification settings - Fork 8k
uri: Do not pass uri_internal_t
to property handlers
#19805
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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.
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); | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this 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
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 theuri_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.