Repository navigation
Implement Query Parameter Manipulation Support RFC - #22551
kocsismate wants to merge 2 commits into
Conversation
TimWolla
left a comment
There was a problem hiding this comment.
Some comments without trying to understand the logic.
| zend_string *result = zend_string_alloc(str_length, false); | ||
|
|
||
| memcpy(ZSTR_VAL(result), str, str_length); | ||
| ZSTR_VAL(result)[str_length] = '\0'; |
There was a problem hiding this comment.
I think this can also just be zend_string_init().
| } | ||
|
|
||
| if (UNEXPECTED(str_length == 0)) { | ||
| return zend_empty_string; |
| } | ||
| } ZEND_HASH_FOREACH_END(); | ||
|
|
||
| return buf.s != NULL ? smart_str_extract(&buf) : ZSTR_EMPTY_ALLOC(); |
There was a problem hiding this comment.
This optimization is handled automatically:
Lines 104 to 113 in 8613e0e
| options->parsing_max_param_count = parsing_max_param_count; | ||
|
|
||
| if (true_value == NULL) { | ||
| options->true_value = zend_string_init(ZEND_STRL("1"), false); |
| if (true_value == NULL) { | ||
| options->true_value = zend_string_init(ZEND_STRL("1"), false); | ||
| } else { | ||
| options->true_value = true_value; | ||
| } |
There was a problem hiding this comment.
I feel this is more readable.
| if (true_value == NULL) { | |
| options->true_value = zend_string_init(ZEND_STRL("1"), false); | |
| } else { | |
| options->true_value = true_value; | |
| } | |
| if (true_value == NULL) { | |
| true_value = ZSTR_CHAR('1'); | |
| } | |
| options->true_value = true_value; |
| case IS_RESOURCE: | ||
| zend_argument_value_error(2, "must not contain a resource"); | ||
| return NULL; | ||
| case IS_ARRAY: { |
There was a problem hiding this comment.
Very inconsistent use of braces. They are not needed in the majority of cases.
| return NULL; | ||
| } | ||
| case IS_OBJECT: | ||
| if (Z_OBJCE_P(zv)->ce_flags & ZEND_ACC_ENUM && Z_OBJCE_P(zv)->enum_backing_type != IS_UNDEF) { |
There was a problem hiding this comment.
| if (Z_OBJCE_P(zv)->ce_flags & ZEND_ACC_ENUM && Z_OBJCE_P(zv)->enum_backing_type != IS_UNDEF) { | |
| if ((Z_OBJCE_P(zv)->ce_flags & ZEND_ACC_ENUM) && Z_OBJCE_P(zv)->enum_backing_type != IS_UNDEF) { |
|
|
||
| if ( | ||
| (value == NULL && list_entry->value == NULL) || | ||
| (value != NULL && list_entry->value != NULL && zend_string_equal_content(value, list_entry->value)) |
There was a problem hiding this comment.
Is there a reason this isn't just?
| (value != NULL && list_entry->value != NULL && zend_string_equal_content(value, list_entry->value)) | |
| (value != NULL && list_entry->value != NULL && zend_string_equal(value, list_entry->value)) |
| return NULL; | ||
| } | ||
|
|
||
| php_uri_query_params_iterator *iterator = emalloc(sizeof(php_uri_query_params_iterator)); |
There was a problem hiding this comment.
| php_uri_query_params_iterator *iterator = emalloc(sizeof(php_uri_query_params_iterator)); | |
| php_uri_query_params_iterator *iterator = emalloc(sizeof(*iterator)); |
5ca5451 to
ee775db
Compare
ee775db to
a6ffe63
Compare
| } | ||
| } ZEND_HASH_FOREACH_END(); | ||
|
|
||
| return buf.s != NULL ? smart_str_extract(&buf) : ZSTR_EMPTY_ALLOC(); |
There was a problem hiding this comment.
smart_str_extract handles this optimization by itself.
| return NULL; | ||
| } | ||
|
|
||
| if (is_first) { |
There was a problem hiding this comment.
You can check smart_str_get_len() > 0 to avoid the extra variable.
| } | ||
| } | ||
|
|
||
| ZSTR_LEN(result) = (size_t)(end - ZSTR_VAL(result)); |
| return zend_string_init(buffer, strlen(buffer), false); | ||
| } | ||
| case IS_OBJECT: | ||
| if (instanceof_function(Z_OBJCE_P(value), zend_ce_backed_enum)) { |
There was a problem hiding this comment.
instanceof is needlessly expensive. Borrow the checks from zend_enum_fetch_case_value.
RFC: https://wiki.php.net/rfc/query_params