Skip to content

Commit d5ad751

Browse files
authored
More usage of known zend_str instead of C string (#11381)
1 parent 962a777 commit d5ad751

38 files changed

+110
-103
lines changed

Zend/zend_API.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3529,7 +3529,7 @@ static bool zend_is_callable_check_class(zend_string *name, zend_class_entry *sc
35293529
*strict_class = 1;
35303530
ret = 1;
35313531
}
3532-
} else if (zend_string_equals_literal(lcname, "static")) {
3532+
} else if (zend_string_equals(lcname, ZSTR_KNOWN(ZEND_STR_STATIC))) {
35333533
zend_class_entry *called_scope = zend_get_called_scope(frame);
35343534

35353535
if (!called_scope) {
@@ -4560,7 +4560,7 @@ ZEND_API zend_class_constant *zend_declare_typed_class_constant(zend_class_entry
45604560
}
45614561
}
45624562

4563-
if (zend_string_equals_literal_ci(name, "class")) {
4563+
if (zend_string_equals_ci(name, ZSTR_KNOWN(ZEND_STR_CLASS))) {
45644564
zend_error_noreturn(ce->type == ZEND_INTERNAL_CLASS ? E_CORE_ERROR : E_COMPILE_ERROR,
45654565
"A class constant must not be called 'class'; it is reserved for class name fetching");
45664566
}

Zend/zend_ast.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ ZEND_API zend_ast * ZEND_FASTCALL zend_ast_create_constant(zend_string *name, ze
101101

102102
ZEND_API zend_ast * ZEND_FASTCALL zend_ast_create_class_const_or_name(zend_ast *class_name, zend_ast *name) {
103103
zend_string *name_str = zend_ast_get_str(name);
104-
if (zend_string_equals_literal_ci(name_str, "class")) {
104+
if (zend_string_equals_ci(name_str, ZSTR_KNOWN(ZEND_STR_CLASS))) {
105105
zend_string_release(name_str);
106106
return zend_ast_create(ZEND_AST_CLASS_NAME, class_name);
107107
} else {

Zend/zend_attributes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ ZEND_METHOD(SensitiveParameterValue, __construct)
114114
Z_PARAM_ZVAL(value)
115115
ZEND_PARSE_PARAMETERS_END();
116116

117-
zend_update_property(zend_ce_sensitive_parameter_value, Z_OBJ_P(ZEND_THIS), "value", strlen("value"), value);
117+
zend_update_property_ex(zend_ce_sensitive_parameter_value, Z_OBJ_P(ZEND_THIS), ZSTR_KNOWN(ZEND_STR_VALUE), value);
118118
}
119119

120120
ZEND_METHOD(SensitiveParameterValue, getValue)

Zend/zend_builtin_functions.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1322,7 +1322,7 @@ ZEND_FUNCTION(get_defined_functions)
13221322
} ZEND_HASH_FOREACH_END();
13231323

13241324
zend_hash_str_add_new(Z_ARRVAL_P(return_value), "internal", sizeof("internal")-1, &internal);
1325-
zend_hash_str_add_new(Z_ARRVAL_P(return_value), "user", sizeof("user")-1, &user);
1325+
zend_hash_add_new(Z_ARRVAL_P(return_value), ZSTR_KNOWN(ZEND_STR_USER), &user);
13261326
}
13271327
/* }}} */
13281328

Zend/zend_compile.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,7 +1429,7 @@ ZEND_API zend_string *zend_type_to_string(zend_type type) {
14291429
}
14301430

14311431
static bool is_generator_compatible_class_type(zend_string *name) {
1432-
return zend_string_equals_literal_ci(name, "Traversable")
1432+
return zend_string_equals_ci(name, ZSTR_KNOWN(ZEND_STR_TRAVERSABLE))
14331433
|| zend_string_equals_literal_ci(name, "Iterator")
14341434
|| zend_string_equals_literal_ci(name, "Generator");
14351435
}
@@ -1617,7 +1617,7 @@ uint32_t zend_get_class_fetch_type(const zend_string *name) /* {{{ */
16171617
return ZEND_FETCH_CLASS_SELF;
16181618
} else if (zend_string_equals_literal_ci(name, "parent")) {
16191619
return ZEND_FETCH_CLASS_PARENT;
1620-
} else if (zend_string_equals_literal_ci(name, "static")) {
1620+
} else if (zend_string_equals_ci(name, ZSTR_KNOWN(ZEND_STR_STATIC))) {
16211621
return ZEND_FETCH_CLASS_STATIC;
16221622
} else {
16231623
return ZEND_FETCH_CLASS_DEFAULT;
@@ -2821,7 +2821,7 @@ static bool is_this_fetch(zend_ast *ast) /* {{{ */
28212821
{
28222822
if (ast->kind == ZEND_AST_VAR && ast->child[0]->kind == ZEND_AST_ZVAL) {
28232823
zval *name = zend_ast_get_zval(ast->child[0]);
2824-
return Z_TYPE_P(name) == IS_STRING && zend_string_equals_literal(Z_STR_P(name), "this");
2824+
return Z_TYPE_P(name) == IS_STRING && zend_string_equals(Z_STR_P(name), ZSTR_KNOWN(ZEND_STR_THIS));
28252825
}
28262826

28272827
return 0;
@@ -4522,7 +4522,7 @@ static zend_result zend_try_compile_special_func(znode *result, zend_string *lcn
45224522
return zend_compile_func_cuf(result, args, lcname);
45234523
} else if (zend_string_equals_literal(lcname, "in_array")) {
45244524
return zend_compile_func_in_array(result, args);
4525-
} else if (zend_string_equals_literal(lcname, "count")
4525+
} else if (zend_string_equals(lcname, ZSTR_KNOWN(ZEND_STR_COUNT))
45264526
|| zend_string_equals_literal(lcname, "sizeof")) {
45274527
return zend_compile_func_count(result, args, lcname);
45284528
} else if (zend_string_equals_literal(lcname, "get_class")) {
@@ -4872,7 +4872,7 @@ static void zend_compile_static_var_common(zend_string *var_name, zval *value, u
48724872

48734873
value = zend_hash_update(CG(active_op_array)->static_variables, var_name, value);
48744874

4875-
if (zend_string_equals_literal(var_name, "this")) {
4875+
if (zend_string_equals(var_name, ZSTR_KNOWN(ZEND_STR_THIS))) {
48764876
zend_error_noreturn(E_COMPILE_ERROR, "Cannot use $this as static variable");
48774877
}
48784878

@@ -4888,7 +4888,7 @@ static void zend_compile_static_var(zend_ast *ast) /* {{{ */
48884888
zend_ast *var_ast = ast->child[0];
48894889
zend_string *var_name = zend_ast_get_str(var_ast);
48904890

4891-
if (zend_string_equals_literal(var_name, "this")) {
4891+
if (zend_string_equals(var_name, ZSTR_KNOWN(ZEND_STR_THIS))) {
48924892
zend_error_noreturn(E_COMPILE_ERROR, "Cannot use $this as static variable");
48934893
}
48944894

@@ -6089,7 +6089,7 @@ static void zend_compile_try(zend_ast *ast) /* {{{ */
60896089
zend_resolve_class_name_ast(class_ast));
60906090
opline->extended_value = zend_alloc_cache_slot();
60916091

6092-
if (var_name && zend_string_equals_literal(var_name, "this")) {
6092+
if (var_name && zend_string_equals(var_name, ZSTR_KNOWN(ZEND_STR_THIS))) {
60936093
zend_error_noreturn(E_COMPILE_ERROR, "Cannot re-assign $this");
60946094
}
60956095

@@ -6925,7 +6925,7 @@ static void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast, uint32
69256925
if (EX_VAR_TO_NUM(var_node.u.op.var) != i) {
69266926
zend_error_noreturn(E_COMPILE_ERROR, "Redefinition of parameter $%s",
69276927
ZSTR_VAL(name));
6928-
} else if (zend_string_equals_literal(name, "this")) {
6928+
} else if (zend_string_equals(name, ZSTR_KNOWN(ZEND_STR_THIS))) {
69296929
zend_error_noreturn(E_COMPILE_ERROR, "Cannot use $this as parameter");
69306930
}
69316931

@@ -7152,7 +7152,7 @@ static void zend_compile_closure_binding(znode *closure, zend_op_array *op_array
71527152
zend_op *opline;
71537153
zval *value;
71547154

7155-
if (zend_string_equals_literal(var_name, "this")) {
7155+
if (zend_string_equals(var_name, ZSTR_KNOWN(ZEND_STR_THIS))) {
71567156
zend_error_noreturn(E_COMPILE_ERROR, "Cannot use $this as lexical variable");
71577157
}
71587158

@@ -7196,7 +7196,7 @@ static void find_implicit_binds_recursively(closure_info *info, zend_ast *ast) {
71967196
return;
71977197
}
71987198

7199-
if (zend_string_equals_literal(name, "this")) {
7199+
if (zend_string_equals(name, ZSTR_KNOWN(ZEND_STR_THIS))) {
72007200
/* $this does not need to be explicitly imported. */
72017201
return;
72027202
}

Zend/zend_constants.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ ZEND_API zval *zend_get_class_constant_ex(zend_string *class_name, zend_string *
314314
} else {
315315
ce = scope->parent;
316316
}
317-
} else if (zend_string_equals_literal_ci(class_name, "static")) {
317+
} else if (zend_string_equals_ci(class_name, ZSTR_KNOWN(ZEND_STR_STATIC))) {
318318
ce = zend_get_called_scope(EG(current_execute_data));
319319
if (UNEXPECTED(!ce)) {
320320
zend_throw_error(NULL, "Cannot access \"static\" when no class scope is active");
@@ -419,7 +419,7 @@ ZEND_API zval *zend_get_constant_ex(zend_string *cname, zend_class_entry *scope,
419419
} else {
420420
ce = scope->parent;
421421
}
422-
} else if (zend_string_equals_literal_ci(class_name, "static")) {
422+
} else if (zend_string_equals_ci(class_name, ZSTR_KNOWN(ZEND_STR_STATIC))) {
423423
ce = zend_get_called_scope(EG(current_execute_data));
424424
if (UNEXPECTED(!ce)) {
425425
zend_throw_error(NULL, "Cannot access \"static\" when no class scope is active");

Zend/zend_enum.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ static void zend_verify_enum_properties(zend_class_entry *ce)
6262
zend_property_info *property_info;
6363

6464
ZEND_HASH_MAP_FOREACH_PTR(&ce->properties_info, property_info) {
65-
if (zend_string_equals_literal(property_info->name, "name")) {
65+
if (zend_string_equals(property_info->name, ZSTR_KNOWN(ZEND_STR_NAME))) {
6666
continue;
6767
}
6868
if (
6969
ce->enum_backing_type != IS_UNDEF
70-
&& zend_string_equals_literal(property_info->name, "value")
70+
&& zend_string_equals(property_info->name, ZSTR_KNOWN(ZEND_STR_VALUE))
7171
) {
7272
continue;
7373
}

Zend/zend_interfaces.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,8 @@ static int zend_implement_iterator(zend_class_entry *interface, zend_class_entry
344344
&class_type->function_table, "rewind", sizeof("rewind") - 1);
345345
funcs_ptr->zf_valid = zend_hash_str_find_ptr(
346346
&class_type->function_table, "valid", sizeof("valid") - 1);
347-
funcs_ptr->zf_key = zend_hash_str_find_ptr(
348-
&class_type->function_table, "key", sizeof("key") - 1);
347+
funcs_ptr->zf_key = zend_hash_find_ptr(
348+
&class_type->function_table, ZSTR_KNOWN(ZEND_STR_KEY));
349349
funcs_ptr->zf_current = zend_hash_str_find_ptr(
350350
&class_type->function_table, "current", sizeof("current") - 1);
351351
funcs_ptr->zf_next = zend_hash_str_find_ptr(

ext/curl/interface.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1377,7 +1377,7 @@ static inline zend_result build_mime_structure_from_hash(php_curl *ch, zval *zpo
13771377
curl_seek_callback seekfunc = seek_cb;
13781378
#endif
13791379

1380-
prop = zend_read_property(curl_CURLFile_class, Z_OBJ_P(current), "name", sizeof("name")-1, 0, &rv);
1380+
prop = zend_read_property_ex(curl_CURLFile_class, Z_OBJ_P(current), ZSTR_KNOWN(ZEND_STR_NAME), /* silent */ false, &rv);
13811381
ZVAL_DEREF(prop);
13821382
if (Z_TYPE_P(prop) != IS_STRING) {
13831383
php_error_docref(NULL, E_WARNING, "Invalid filename for key %s", ZSTR_VAL(string_key));

ext/dom/node.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1622,7 +1622,8 @@ static void dom_canonicalization(INTERNAL_FUNCTION_PARAMETERS, int mode) /* {{{
16221622
zval *tmp;
16231623
char *xquery;
16241624

1625-
tmp = zend_hash_str_find(ht, "query", sizeof("query")-1);
1625+
/* Find "query" key */
1626+
tmp = zend_hash_find(ht, ZSTR_KNOWN(ZEND_STR_QUERY));
16261627
if (!tmp) {
16271628
/* if mode == 0 then $xpath arg is 3, if mode == 1 then $xpath is 4 */
16281629
zend_argument_value_error(3 + mode, "must have a \"query\" key");

0 commit comments

Comments
 (0)