Skip to content

Commit d7c45b1

Browse files
committed
Merge pull request godotengine#118813 from NoctemCat/gdscript_vm_reduce_ref_changes
[GDScript] Reduce changes in refcounts in GDScript VM
2 parents 10ba06c + 8f90102 commit d7c45b1

1 file changed

Lines changed: 16 additions & 16 deletions

File tree

modules/gdscript/gdscript_vm.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ static bool _profile_count_as_native(const Object *p_base_obj, const StringName
4242
if (!p_base_obj) {
4343
return false;
4444
}
45-
StringName cname = p_base_obj->get_class_name();
46-
if ((p_methodname == "new" && cname == "GDScript") || p_methodname == "call") {
45+
const StringName &cname = p_base_obj->get_class_name();
46+
if ((p_methodname == SNAME("new") && cname == GDScript::get_class_static()) || p_methodname == CoreStringName(call)) {
4747
return false;
4848
}
4949
return ClassDB::class_exists(cname) && ClassDB::has_method(cname, p_methodname, false);
@@ -881,7 +881,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
881881
Variant::Type builtin_type = (Variant::Type)_code_ptr[ip + 4];
882882
int native_type_idx = _code_ptr[ip + 5];
883883
GD_ERR_BREAK(native_type_idx < 0 || native_type_idx >= _global_names_count);
884-
const StringName native_type = _global_names_ptr[native_type_idx];
884+
const StringName &native_type = _global_names_ptr[native_type_idx];
885885

886886
bool result = false;
887887
if (value->get_type() == Variant::ARRAY) {
@@ -904,13 +904,13 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
904904
Variant::Type key_builtin_type = (Variant::Type)_code_ptr[ip + 5];
905905
int key_native_type_idx = _code_ptr[ip + 6];
906906
GD_ERR_BREAK(key_native_type_idx < 0 || key_native_type_idx >= _global_names_count);
907-
const StringName key_native_type = _global_names_ptr[key_native_type_idx];
907+
const StringName &key_native_type = _global_names_ptr[key_native_type_idx];
908908

909909
GET_VARIANT_PTR(value_script_type, 3);
910910
Variant::Type value_builtin_type = (Variant::Type)_code_ptr[ip + 7];
911911
int value_native_type_idx = _code_ptr[ip + 8];
912912
GD_ERR_BREAK(value_native_type_idx < 0 || value_native_type_idx >= _global_names_count);
913-
const StringName value_native_type = _global_names_ptr[value_native_type_idx];
913+
const StringName &value_native_type = _global_names_ptr[value_native_type_idx];
914914

915915
bool result = false;
916916
if (value->get_type() == Variant::DICTIONARY) {
@@ -932,7 +932,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
932932

933933
int native_type_idx = _code_ptr[ip + 3];
934934
GD_ERR_BREAK(native_type_idx < 0 || native_type_idx >= _global_names_count);
935-
const StringName native_type = _global_names_ptr[native_type_idx];
935+
const StringName &native_type = _global_names_ptr[native_type_idx];
936936

937937
bool was_freed = false;
938938
Object *object = value->get_validated_object_with_check(was_freed);
@@ -1455,7 +1455,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
14551455
Variant::Type builtin_type = (Variant::Type)_code_ptr[ip + 4];
14561456
int native_type_idx = _code_ptr[ip + 5];
14571457
GD_ERR_BREAK(native_type_idx < 0 || native_type_idx >= _global_names_count);
1458-
const StringName native_type = _global_names_ptr[native_type_idx];
1458+
const StringName &native_type = _global_names_ptr[native_type_idx];
14591459

14601460
if (src->get_type() != Variant::ARRAY) {
14611461
#ifdef DEBUG_ENABLED
@@ -1490,13 +1490,13 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
14901490
Variant::Type key_builtin_type = (Variant::Type)_code_ptr[ip + 5];
14911491
int key_native_type_idx = _code_ptr[ip + 6];
14921492
GD_ERR_BREAK(key_native_type_idx < 0 || key_native_type_idx >= _global_names_count);
1493-
const StringName key_native_type = _global_names_ptr[key_native_type_idx];
1493+
const StringName &key_native_type = _global_names_ptr[key_native_type_idx];
14941494

14951495
GET_VARIANT_PTR(value_script_type, 3);
14961496
Variant::Type value_builtin_type = (Variant::Type)_code_ptr[ip + 7];
14971497
int value_native_type_idx = _code_ptr[ip + 8];
14981498
GD_ERR_BREAK(value_native_type_idx < 0 || value_native_type_idx >= _global_names_count);
1499-
const StringName value_native_type = _global_names_ptr[value_native_type_idx];
1499+
const StringName &value_native_type = _global_names_ptr[value_native_type_idx];
15001500

15011501
if (src->get_type() != Variant::DICTIONARY) {
15021502
#ifdef DEBUG_ENABLED
@@ -1810,7 +1810,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
18101810
Variant::Type builtin_type = (Variant::Type)_code_ptr[ip + 2];
18111811
int native_type_idx = _code_ptr[ip + 3];
18121812
GD_ERR_BREAK(native_type_idx < 0 || native_type_idx >= _global_names_count);
1813-
const StringName native_type = _global_names_ptr[native_type_idx];
1813+
const StringName &native_type = _global_names_ptr[native_type_idx];
18141814

18151815
Array array;
18161816
array.set_typed(builtin_type, native_type, *script_type);
@@ -1865,13 +1865,13 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
18651865
Variant::Type key_builtin_type = (Variant::Type)_code_ptr[ip + 2];
18661866
int key_native_type_idx = _code_ptr[ip + 3];
18671867
GD_ERR_BREAK(key_native_type_idx < 0 || key_native_type_idx >= _global_names_count);
1868-
const StringName key_native_type = _global_names_ptr[key_native_type_idx];
1868+
const StringName &key_native_type = _global_names_ptr[key_native_type_idx];
18691869

18701870
GET_INSTRUCTION_ARG(value_script_type, argc * 2 + 2);
18711871
Variant::Type value_builtin_type = (Variant::Type)_code_ptr[ip + 4];
18721872
int value_native_type_idx = _code_ptr[ip + 5];
18731873
GD_ERR_BREAK(value_native_type_idx < 0 || value_native_type_idx >= _global_names_count);
1874-
const StringName value_native_type = _global_names_ptr[value_native_type_idx];
1874+
const StringName &value_native_type = _global_names_ptr[value_native_type_idx];
18751875

18761876
Dictionary dict;
18771877
dict.set_typed(key_builtin_type, key_native_type, *key_script_type, value_builtin_type, value_native_type, *value_script_type);
@@ -2404,7 +2404,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
24042404
GD_ERR_BREAK(argc < 0);
24052405

24062406
GD_ERR_BREAK(_code_ptr[ip + 2] < 0 || _code_ptr[ip + 2] >= _global_names_count);
2407-
StringName function = _global_names_ptr[_code_ptr[ip + 2]];
2407+
const StringName &function = _global_names_ptr[_code_ptr[ip + 2]];
24082408

24092409
Variant **argptrs = instruction_args;
24102410

@@ -2843,7 +2843,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
28432843
Variant::Type builtin_type = (Variant::Type)_code_ptr[ip + 3];
28442844
int native_type_idx = _code_ptr[ip + 4];
28452845
GD_ERR_BREAK(native_type_idx < 0 || native_type_idx >= _global_names_count);
2846-
const StringName native_type = _global_names_ptr[native_type_idx];
2846+
const StringName &native_type = _global_names_ptr[native_type_idx];
28472847

28482848
if (r->get_type() != Variant::ARRAY) {
28492849
#ifdef DEBUG_ENABLED
@@ -2879,13 +2879,13 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
28792879
Variant::Type key_builtin_type = (Variant::Type)_code_ptr[ip + 4];
28802880
int key_native_type_idx = _code_ptr[ip + 5];
28812881
GD_ERR_BREAK(key_native_type_idx < 0 || key_native_type_idx >= _global_names_count);
2882-
const StringName key_native_type = _global_names_ptr[key_native_type_idx];
2882+
const StringName &key_native_type = _global_names_ptr[key_native_type_idx];
28832883

28842884
GET_VARIANT_PTR(value_script_type, 2);
28852885
Variant::Type value_builtin_type = (Variant::Type)_code_ptr[ip + 6];
28862886
int value_native_type_idx = _code_ptr[ip + 7];
28872887
GD_ERR_BREAK(value_native_type_idx < 0 || value_native_type_idx >= _global_names_count);
2888-
const StringName value_native_type = _global_names_ptr[value_native_type_idx];
2888+
const StringName &value_native_type = _global_names_ptr[value_native_type_idx];
28892889

28902890
if (r->get_type() != Variant::DICTIONARY) {
28912891
#ifdef DEBUG_ENABLED

0 commit comments

Comments
 (0)