mirror of
https://github.com/godotengine/godot.git
synced 2025-10-19 16:03:29 +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
|
@ -73,7 +73,7 @@ void PHashTranslation::generate(const Ref<Translation> &p_from) {
|
|||
Pair<int, CharString> p;
|
||||
p.first = idx;
|
||||
p.second = cs;
|
||||
buckets[h % size].push_back(p);
|
||||
buckets.write[h % size].push_back(p);
|
||||
|
||||
//compress string
|
||||
CharString src_s = p_from->get_message(E->get()).operator String().utf8();
|
||||
|
@ -100,7 +100,7 @@ void PHashTranslation::generate(const Ref<Translation> &p_from) {
|
|||
ps.compressed[0] = 0;
|
||||
}
|
||||
|
||||
compressed[idx] = ps;
|
||||
compressed.write[idx] = ps;
|
||||
total_compression_size += ps.compressed.size();
|
||||
total_string_size += src_s.size();
|
||||
idx++;
|
||||
|
@ -111,8 +111,8 @@ void PHashTranslation::generate(const Ref<Translation> &p_from) {
|
|||
|
||||
for (int i = 0; i < size; i++) {
|
||||
|
||||
Vector<Pair<int, CharString> > &b = buckets[i];
|
||||
Map<uint32_t, int> &t = table[i];
|
||||
const Vector<Pair<int, CharString> > &b = buckets[i];
|
||||
Map<uint32_t, int> &t = table.write[i];
|
||||
|
||||
if (b.size() == 0)
|
||||
continue;
|
||||
|
@ -136,7 +136,7 @@ void PHashTranslation::generate(const Ref<Translation> &p_from) {
|
|||
}
|
||||
}
|
||||
|
||||
hfunc_table[i] = d;
|
||||
hfunc_table.write[i] = d;
|
||||
bucket_table_size += 2 + b.size() * 4;
|
||||
}
|
||||
|
||||
|
@ -157,7 +157,7 @@ void PHashTranslation::generate(const Ref<Translation> &p_from) {
|
|||
|
||||
for (int i = 0; i < size; i++) {
|
||||
|
||||
Map<uint32_t, int> &t = table[i];
|
||||
const Map<uint32_t, int> &t = table[i];
|
||||
if (t.size() == 0) {
|
||||
htw[i] = 0xFFFFFFFF; //nothing
|
||||
continue;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue