ext/reflection: various cleanups and simplifications (2)#22660
ext/reflection: various cleanups and simplifications (2)#22660DanielEScherzer wants to merge 11 commits into
Conversation
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.
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, rather than building up the string in pieces (first the indented `Property [ `, then the `<dynamic> public` followed by the name, and finally the closing ` ]\n`) use a single `smart_str_append_printf()` call and 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.
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.
| ce = Z_OBJCE_P(reference); | ||
|
|
||
| if (instanceof_function(ce, zend_ce_closure)) { | ||
| if (ce == zend_ce_closure) { |
There was a problem hiding this comment.
Might be good to add a comment just to explain it. As instanceof_function() is always inlined to do this pointer comparison and only call the outlined slow function if not true.
| } ZEND_HASH_FOREACH_END(); | ||
|
|
||
| if (instanceof_function(ce, zend_ce_closure)) { | ||
| if (ce == zend_ce_closure) { |
There was a problem hiding this comment.
Ditto, probably should be a single commit with all the zend_ce_closure checks rather than multiple.
| 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.
| object_init_ex(object, reflection_attribute_ptr); | ||
| intern = Z_REFLECTION_P(object); | ||
| reference = (attribute_reference*) emalloc(sizeof(attribute_reference)); | ||
| reflection_object *intern = Z_REFLECTION_P(object); |
There was a problem hiding this comment.
Nit: two spaces (or tabs?) after the variable name and the = sign which are not aligned anyway.
| 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.
No description provided.