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:
Hein-Pieter van Braam 2018-07-25 03:11:03 +02:00
parent 9423f23ffb
commit 0e29f7974b
228 changed files with 2200 additions and 2082 deletions

View file

@ -187,7 +187,7 @@ void EditorExportPreset::remove_patch(int p_idx) {
void EditorExportPreset::set_patch(int p_index, const String &p_path) {
ERR_FAIL_INDEX(p_index, patches.size());
patches[p_index] = p_path;
patches.write[p_index] = p_path;
EditorExport::singleton->save_presets();
}
String EditorExportPreset::get_patch(int p_index) {
@ -295,7 +295,7 @@ Error EditorExportPlatform::_save_pack_file(void *p_userdata, const String &p_pa
MD5Final(&ctx);
sd.md5.resize(16);
for (int i = 0; i < 16; i++) {
sd.md5[i] = ctx.digest[i];
sd.md5.write[i] = ctx.digest[i];
}
}
@ -584,9 +584,9 @@ EditorExportPlatform::ExportNotifier::ExportNotifier(EditorExportPlatform &p_pla
//initial export plugin callback
for (int i = 0; i < export_plugins.size(); i++) {
if (export_plugins[i]->get_script_instance()) { //script based
export_plugins[i]->_export_begin_script(features.features_pv, p_debug, p_path, p_flags);
export_plugins.write[i]->_export_begin_script(features.features_pv, p_debug, p_path, p_flags);
} else {
export_plugins[i]->_export_begin(features.features, p_debug, p_path, p_flags);
export_plugins.write[i]->_export_begin(features.features, p_debug, p_path, p_flags);
}
}
}
@ -594,7 +594,7 @@ EditorExportPlatform::ExportNotifier::ExportNotifier(EditorExportPlatform &p_pla
EditorExportPlatform::ExportNotifier::~ExportNotifier() {
Vector<Ref<EditorExportPlugin> > export_plugins = EditorExport::get_singleton()->get_export_plugins();
for (int i = 0; i < export_plugins.size(); i++) {
export_plugins[i]->_export_end();
export_plugins.write[i]->_export_end();
}
}
@ -632,7 +632,7 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> &
p_func(p_udata, export_plugins[i]->extra_files[j].path, export_plugins[i]->extra_files[j].data, 0, paths.size());
}
export_plugins[i]->_clear();
export_plugins.write[i]->_clear();
}
FeatureContainers feature_containers = get_feature_containers(p_preset);
@ -687,9 +687,9 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> &
bool do_export = true;
for (int i = 0; i < export_plugins.size(); i++) {
if (export_plugins[i]->get_script_instance()) { //script based
export_plugins[i]->_export_file_script(path, type, features_pv);
export_plugins.write[i]->_export_file_script(path, type, features_pv);
} else {
export_plugins[i]->_export_file(path, type, features);
export_plugins.write[i]->_export_file(path, type, features);
}
if (p_so_func) {
for (int j = 0; j < export_plugins[i]->shared_objects.size(); j++) {
@ -709,7 +709,7 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> &
if (export_plugins[i]->skipped) {
do_export = false;
}
export_plugins[i]->_clear();
export_plugins.write[i]->_clear();
if (!do_export)
break; //apologies, not exporting
@ -751,7 +751,7 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> &
Vector<uint8_t> new_file;
new_file.resize(utf8.length());
for (int j = 0; j < utf8.length(); j++) {
new_file[j] = utf8[j];
new_file.write[j] = utf8[j];
}
p_func(p_udata, from + ".remap", new_file, idx, total);
@ -1130,7 +1130,7 @@ void EditorExport::load_config() {
for (int i = 0; i < export_platforms.size(); i++) {
if (export_platforms[i]->get_name() == platform) {
preset = export_platforms[i]->create_preset();
preset = export_platforms.write[i]->create_preset();
break;
}
}
@ -1203,7 +1203,7 @@ bool EditorExport::poll_export_platforms() {
bool changed = false;
for (int i = 0; i < export_platforms.size(); i++) {
if (export_platforms[i]->poll_devices()) {
if (export_platforms.write[i]->poll_devices()) {
changed = true;
}
}