mirror of
https://github.com/godotengine/godot.git
synced 2025-10-20 00:13:30 +00:00
Reduce unnecessary COW on Vector by make writing explicit
This commit makes operator[] on Vector const and adds a write proxy to it. From now on writes to Vectors need to happen through the .write proxy. So for instance: Vector<int> vec; vec.push_back(10); std::cout << vec[0] << std::endl; vec.write[0] = 20; Failing to use the .write proxy will cause a compilation error. In addition COWable datatypes can now embed a CowData pointer to their data. This means that String, CharString, and VMap no longer use or derive from Vector. _ALWAYS_INLINE_ and _FORCE_INLINE_ are now equivalent for debug and non-debug builds. This is a lot faster for Vector in the editor and while running tests. The reason why this difference used to exist is because force-inlined methods used to give a bad debugging experience. After extensive testing with modern compilers this is no longer the case.
This commit is contained in:
parent
9423f23ffb
commit
0e29f7974b
228 changed files with 2200 additions and 2082 deletions
|
@ -1157,8 +1157,8 @@ int NativeScriptLanguage::register_binding_functions(godot_instance_binding_func
|
|||
}
|
||||
|
||||
// set the functions
|
||||
binding_functions[idx].first = true;
|
||||
binding_functions[idx].second = p_binding_functions;
|
||||
binding_functions.write[idx].first = true;
|
||||
binding_functions.write[idx].second = p_binding_functions;
|
||||
|
||||
return idx;
|
||||
}
|
||||
|
@ -1173,7 +1173,7 @@ void NativeScriptLanguage::unregister_binding_functions(int p_idx) {
|
|||
binding_functions[p_idx].second.free_instance_binding_data(binding_functions[p_idx].second.data, binding_data[p_idx]);
|
||||
}
|
||||
|
||||
binding_functions[p_idx].first = false;
|
||||
binding_functions.write[p_idx].first = false;
|
||||
|
||||
if (binding_functions[p_idx].second.free_func)
|
||||
binding_functions[p_idx].second.free_func(binding_functions[p_idx].second.data);
|
||||
|
@ -1199,7 +1199,7 @@ void *NativeScriptLanguage::get_instance_binding_data(int p_idx, Object *p_objec
|
|||
binding_data->resize(p_idx + 1);
|
||||
|
||||
for (int i = old_size; i <= p_idx; i++) {
|
||||
(*binding_data)[i] = NULL;
|
||||
(*binding_data).write[i] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1208,7 +1208,7 @@ void *NativeScriptLanguage::get_instance_binding_data(int p_idx, Object *p_objec
|
|||
const void *global_type_tag = global_type_tags[p_idx].get(p_object->get_class_name());
|
||||
|
||||
// no binding data yet, soooooo alloc new one \o/
|
||||
(*binding_data)[p_idx] = binding_functions[p_idx].second.alloc_instance_binding_data(binding_functions[p_idx].second.data, global_type_tag, (godot_object *)p_object);
|
||||
(*binding_data).write[p_idx] = binding_functions[p_idx].second.alloc_instance_binding_data(binding_functions[p_idx].second.data, global_type_tag, (godot_object *)p_object);
|
||||
}
|
||||
|
||||
return (*binding_data)[p_idx];
|
||||
|
@ -1221,7 +1221,7 @@ void *NativeScriptLanguage::alloc_instance_binding_data(Object *p_object) {
|
|||
binding_data->resize(binding_functions.size());
|
||||
|
||||
for (int i = 0; i < binding_functions.size(); i++) {
|
||||
(*binding_data)[i] = NULL;
|
||||
(*binding_data).write[i] = NULL;
|
||||
}
|
||||
|
||||
binding_instances.insert(binding_data);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue