ext/reflection: various cleanups and simplifications (2)#22660
ext/reflection: various cleanups and simplifications (2)#22660DanielEScherzer wants to merge 10 commits into
Conversation
Girgias
left a comment
There was a problem hiding this comment.
Did the review commit by commit. And found some orthogonal issues that can be fixed here or in a follow-up PR.
| if (!prop) { | ||
| // Dynamic property, known to have no doc comment, flags, etc. | ||
| smart_str_append_printf(str, "%sProperty [ <dynamic> public $%s ]\n", indent, prop_name); | ||
| return; | ||
| } | ||
| if (prop->doc_comment) { | ||
| smart_str_append_printf(str, "%s%s\n", indent, ZSTR_VAL(prop->doc_comment)); | ||
| } | ||
| smart_str_append_printf(str, "%sProperty [ ", indent); |
There was a problem hiding this comment.
Would it make sense to have a smart_str_appends(str, indent); call before either of the smart_str_append_printf(), as I'm not really the biggest fan of the printf variants personally. But no big opinion here.
| zval *object = ZEND_THIS; | ||
| reflection_object *intern = Z_REFLECTION_P(object); |
There was a problem hiding this comment.
Is the object zval even used somewhere else? Might be better to just do Z_REFLECTION_P(ZEND_THIS);
| if (ini_entry->modifiable == ZEND_INI_ALL) { | ||
| smart_str_appends(str, "ALL"); | ||
| } else { | ||
| char *comma = ""; |
| } | ||
|
|
||
| zval *params; | ||
| int num_args; |
| RETURN_THROWS(); | ||
| } | ||
|
|
||
| int argc = 0; |
| zend_class_entry *ce; | ||
| if (NULL == (ce = zend_lookup_class(attr->data->name))) { |
There was a problem hiding this comment.
Could be rewritten as:
zend_class_entry *ce = zend_lookup_class(attr->data->name);
if (ce == NULL) {
| zend_string *mname = zend_string_alloc(ZSTR_LEN(class_name) + ZSTR_LEN(cur_ref->method_name) + 2, false); | ||
| snprintf(ZSTR_VAL(mname), ZSTR_LEN(mname) + 1, "%s::%s", ZSTR_VAL(class_name), ZSTR_VAL(cur_ref->method_name)); |
There was a problem hiding this comment.
Aside: This feels this would be safer if it was a simple zend_strpprintf.
Optimize - `ReflectionParameter::__construct()` - `ReflectionClass::getMethods()` Given that the `Closure` class is declared as `final`, for some class entry `ce` to represent an instance of a `Closure` it must be exactly `zend_ce_closure`. Replace the `instanceof_function()` call with a simple pointer comparison.
While different callers provided different levels of indentation to the function, the indentation was never used. Remove the parameter and update callers.
…mon` Internal and userland functions store their documentation comments the same way, as a `zend_string` pointer. These pointers are part of the common elements at the start of both `zend_op_array` and `zend_internal_function` that are made available via `zend_function.common`; use the common access rather than checking for the different types of functions individually.
…ng()` For dynamic properties all of the representation details are known immediately, skip the checks for comments, flags, types, defaults, and hooks and use an early return.
When a variable has a single consistent initialization location, move the declaration to be combined with the initialization.
Move variable declarations into the loop start macro where possible to have the types of the variables clear in the loop.
If they cannot be declared at the point of initialization, at least move the declarations closer to where the variables are used.
Consistently indent with tabs, split up some long lines, combine some nested conditions, and overall try to improve readability.
6e5dc76 to
54d8366
Compare
|
Rebased and updated for some of the comments |
No description provided.