Skip to content

Commit 0006522

Browse files
Reflection: optimize smart_str building
- When appending a single character to the string, use `smart_str_appendc()` - When appending a C-string without printf use, use `smart_str_appends()` - When appending just a `zend_string`, use `smart_str_append()`
1 parent 99f72fa commit 0006522

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

ext/reflection/php_reflection.c

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -336,40 +336,40 @@ static void _class_string(smart_str *str, zend_class_entry *ce, zval *obj, const
336336
}
337337
smart_str_append_printf(str, "%s%s [ ", indent, kind);
338338
}
339-
smart_str_append_printf(str, (ce->type == ZEND_USER_CLASS) ? "<user" : "<internal");
339+
smart_str_appends(str, (ce->type == ZEND_USER_CLASS) ? "<user" : "<internal");
340340
if (ce->type == ZEND_INTERNAL_CLASS && ce->info.internal.module) {
341341
smart_str_append_printf(str, ":%s", ce->info.internal.module->name);
342342
}
343-
smart_str_append_printf(str, "> ");
343+
smart_str_appends(str, "> ");
344344
if (ce->get_iterator != NULL) {
345-
smart_str_append_printf(str, "<iterateable> ");
345+
smart_str_appends(str, "<iterateable> ");
346346
}
347347
if (ce->ce_flags & ZEND_ACC_INTERFACE) {
348-
smart_str_append_printf(str, "interface ");
348+
smart_str_appends(str, "interface ");
349349
} else if (ce->ce_flags & ZEND_ACC_TRAIT) {
350-
smart_str_append_printf(str, "trait ");
350+
smart_str_appends(str, "trait ");
351351
} else if (ce->ce_flags & ZEND_ACC_ENUM) {
352-
smart_str_append_printf(str, "enum ");
352+
smart_str_appends(str, "enum ");
353353
} else {
354354
if (ce->ce_flags & (ZEND_ACC_IMPLICIT_ABSTRACT_CLASS|ZEND_ACC_EXPLICIT_ABSTRACT_CLASS)) {
355-
smart_str_append_printf(str, "abstract ");
355+
smart_str_appends(str, "abstract ");
356356
}
357357
if (ce->ce_flags & ZEND_ACC_FINAL) {
358-
smart_str_append_printf(str, "final ");
358+
smart_str_appends(str, "final ");
359359
}
360360
if (ce->ce_flags & ZEND_ACC_READONLY_CLASS) {
361-
smart_str_append_printf(str, "readonly ");
361+
smart_str_appends(str, "readonly ");
362362
}
363-
smart_str_append_printf(str, "class ");
363+
smart_str_appends(str, "class ");
364364
}
365-
smart_str_append_printf(str, "%s", ZSTR_VAL(ce->name));
365+
smart_str_append(str, ce->name);
366366
if (ce->parent) {
367367
smart_str_append_printf(str, " extends %s", ZSTR_VAL(ce->parent->name));
368368
}
369369

370370
// Show backing type of enums
371371
if ((ce->ce_flags & ZEND_ACC_ENUM) && (ce->enum_backing_type != IS_UNDEF)) {
372-
smart_str_append_printf(str,
372+
smart_str_appends(str,
373373
ce->enum_backing_type == IS_STRING ? ": string" : ": int"
374374
);
375375
}
@@ -386,7 +386,7 @@ static void _class_string(smart_str *str, zend_class_entry *ce, zval *obj, const
386386
smart_str_append_printf(str, ", %s", ZSTR_VAL(ce->interfaces[i]->name));
387387
}
388388
}
389-
smart_str_append_printf(str, " ] {\n");
389+
smart_str_appends(str, " ] {\n");
390390

391391
/* The information where a class is declared is only available for user classes */
392392
if (ce->type == ZEND_USER_CLASS) {
@@ -490,12 +490,12 @@ static void _class_string(smart_str *str, zend_class_entry *ce, zval *obj, const
490490
if ((mptr->common.fn_flags & ZEND_ACC_STATIC)
491491
&& ((mptr->common.fn_flags & ZEND_ACC_PRIVATE) == 0 || mptr->common.scope == ce))
492492
{
493-
smart_str_append_printf(str, "\n");
493+
smart_str_appendc(str, '\n');
494494
_function_string(str, mptr, ce, ZSTR_VAL(sub_indent));
495495
}
496496
} ZEND_HASH_FOREACH_END();
497497
} else {
498-
smart_str_append_printf(str, "\n");
498+
smart_str_appendc(str, '\n');
499499
}
500500
smart_str_append_printf(str, "%s }\n", indent);
501501

@@ -566,7 +566,7 @@ static void _class_string(smart_str *str, zend_class_entry *ce, zval *obj, const
566566
smart_str_append_printf(str, "\n%s - Methods [%d] {", indent, count);
567567
smart_str_append_smart_str(str, &method_str);
568568
if (!count) {
569-
smart_str_append_printf(str, "\n");
569+
smart_str_appendc(str, '\n');
570570
}
571571
smart_str_free(&method_str);
572572
} else {
@@ -590,7 +590,7 @@ static void _const_string(smart_str *str, const char *name, zval *value, const c
590590

591591
if (flags & (CONST_PERSISTENT|CONST_NO_FILE_CACHE|CONST_DEPRECATED)) {
592592
bool first = true;
593-
smart_str_appends(str, "<");
593+
smart_str_appendc(str, '<');
594594

595595
#define DUMP_CONST_FLAG(flag, output) \
596596
do { \
@@ -754,7 +754,7 @@ static int format_default_value(smart_str *str, zval *value) {
754754
ZEND_ASSERT(!(class->ce_flags & ZEND_ACC_ENUM));
755755
smart_str_appends(str, "object(");
756756
smart_str_append(str, class->name);
757-
smart_str_appends(str, ")");
757+
smart_str_appendc(str, ')');
758758
} else {
759759
ZEND_ASSERT(Z_TYPE_P(value) == IS_CONSTANT_AST);
760760
zend_string *ast_str = zend_ast_export("", Z_ASTVAL_P(value), "");
@@ -774,9 +774,9 @@ static void _parameter_string(smart_str *str, zend_function *fptr, struct _zend_
774774
{
775775
smart_str_append_printf(str, "Parameter #%d [ ", offset);
776776
if (!required) {
777-
smart_str_append_printf(str, "<optional> ");
777+
smart_str_appends(str, "<optional> ");
778778
} else {
779-
smart_str_append_printf(str, "<required> ");
779+
smart_str_appends(str, "<required> ");
780780
}
781781
if (ZEND_TYPE_IS_SET(arg_info->type)) {
782782
zend_string *type_str = zend_type_to_string(arg_info->type);
@@ -862,7 +862,7 @@ static void _function_closure_string(smart_str *str, const zend_function *fptr,
862862
return;
863863
}
864864

865-
smart_str_append_printf(str, "\n");
865+
smart_str_appendc(str, '\n');
866866
smart_str_append_printf(str, "%s- Bound Variables [%u] {\n", indent, count);
867867
i = 0;
868868
ZEND_HASH_MAP_FOREACH_STR_KEY(static_variables, key) {
@@ -890,8 +890,8 @@ static void _function_string(smart_str *str, zend_function *fptr, zend_class_ent
890890
}
891891

892892
smart_str_appendl(str, indent, strlen(indent));
893-
smart_str_append_printf(str, fptr->common.fn_flags & ZEND_ACC_CLOSURE ? "Closure [ " : (fptr->common.scope ? "Method [ " : "Function [ "));
894-
smart_str_append_printf(str, (fptr->type == ZEND_USER_FUNCTION) ? "<user" : "<internal");
893+
smart_str_appends(str, fptr->common.fn_flags & ZEND_ACC_CLOSURE ? "Closure [ " : (fptr->common.scope ? "Method [ " : "Function [ "));
894+
smart_str_appends(str, (fptr->type == ZEND_USER_FUNCTION) ? "<user" : "<internal");
895895
if (fptr->common.fn_flags & ZEND_ACC_DEPRECATED) {
896896
smart_str_appends(str, ", deprecated");
897897
}
@@ -1102,7 +1102,7 @@ static void _extension_class_string(zend_class_entry *ce, zend_string *key, smar
11021102
if (ce->type == ZEND_INTERNAL_CLASS && ce->info.internal.module && !strcasecmp(ce->info.internal.module->name, module->name)) {
11031103
/* dump class if it is not an alias */
11041104
if (zend_string_equals_ci(ce->name, key)) {
1105-
smart_str_append_printf(str, "\n");
1105+
smart_str_appendc(str, '\n');
11061106
_class_string(str, ce, NULL, indent);
11071107
(*num_classes)++;
11081108
}
@@ -1165,7 +1165,7 @@ static void _extension_string(smart_str *str, const zend_module_entry *module, c
11651165
_extension_ini_string(ini_entry, &str_ini, indent, module->module_number);
11661166
} ZEND_HASH_FOREACH_END();
11671167
if (smart_str_get_len(&str_ini) > 0) {
1168-
smart_str_append_printf(str, "\n - INI {\n");
1168+
smart_str_appends(str, "\n - INI {\n");
11691169
smart_str_append_smart_str(str, &str_ini);
11701170
smart_str_append_printf(str, "%s }\n", indent);
11711171
}
@@ -1200,7 +1200,7 @@ static void _extension_string(smart_str *str, const zend_module_entry *module, c
12001200
if (fptr->common.type==ZEND_INTERNAL_FUNCTION
12011201
&& fptr->internal_function.module == module) {
12021202
if (first) {
1203-
smart_str_append_printf(str, "\n - Functions {\n");
1203+
smart_str_appends(str, "\n - Functions {\n");
12041204
first = 0;
12051205
}
12061206
_function_string(str, fptr, NULL, " ");

0 commit comments

Comments
 (0)