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
|
@ -251,7 +251,7 @@ uint32_t PackedDataContainer::_pack(const Variant &p_data, Vector<uint8_t> &tmpd
|
|||
int len;
|
||||
encode_variant(p_data, NULL, len);
|
||||
tmpdata.resize(tmpdata.size() + len);
|
||||
encode_variant(p_data, &tmpdata[pos], len);
|
||||
encode_variant(p_data, &tmpdata.write[pos], len);
|
||||
return pos;
|
||||
|
||||
} break;
|
||||
|
@ -268,8 +268,8 @@ uint32_t PackedDataContainer::_pack(const Variant &p_data, Vector<uint8_t> &tmpd
|
|||
uint32_t pos = tmpdata.size();
|
||||
int len = d.size();
|
||||
tmpdata.resize(tmpdata.size() + len * 12 + 8);
|
||||
encode_uint32(TYPE_DICT, &tmpdata[pos + 0]);
|
||||
encode_uint32(len, &tmpdata[pos + 4]);
|
||||
encode_uint32(TYPE_DICT, &tmpdata.write[pos + 0]);
|
||||
encode_uint32(len, &tmpdata.write[pos + 4]);
|
||||
|
||||
List<Variant> keys;
|
||||
d.get_key_list(&keys);
|
||||
|
@ -288,11 +288,11 @@ uint32_t PackedDataContainer::_pack(const Variant &p_data, Vector<uint8_t> &tmpd
|
|||
int idx = 0;
|
||||
for (List<DictKey>::Element *E = sortk.front(); E; E = E->next()) {
|
||||
|
||||
encode_uint32(E->get().hash, &tmpdata[pos + 8 + idx * 12 + 0]);
|
||||
encode_uint32(E->get().hash, &tmpdata.write[pos + 8 + idx * 12 + 0]);
|
||||
uint32_t ofs = _pack(E->get().key, tmpdata, string_cache);
|
||||
encode_uint32(ofs, &tmpdata[pos + 8 + idx * 12 + 4]);
|
||||
encode_uint32(ofs, &tmpdata.write[pos + 8 + idx * 12 + 4]);
|
||||
ofs = _pack(d[E->get().key], tmpdata, string_cache);
|
||||
encode_uint32(ofs, &tmpdata[pos + 8 + idx * 12 + 8]);
|
||||
encode_uint32(ofs, &tmpdata.write[pos + 8 + idx * 12 + 8]);
|
||||
idx++;
|
||||
}
|
||||
|
||||
|
@ -306,13 +306,13 @@ uint32_t PackedDataContainer::_pack(const Variant &p_data, Vector<uint8_t> &tmpd
|
|||
uint32_t pos = tmpdata.size();
|
||||
int len = a.size();
|
||||
tmpdata.resize(tmpdata.size() + len * 4 + 8);
|
||||
encode_uint32(TYPE_ARRAY, &tmpdata[pos + 0]);
|
||||
encode_uint32(len, &tmpdata[pos + 4]);
|
||||
encode_uint32(TYPE_ARRAY, &tmpdata.write[pos + 0]);
|
||||
encode_uint32(len, &tmpdata.write[pos + 4]);
|
||||
|
||||
for (int i = 0; i < len; i++) {
|
||||
|
||||
uint32_t ofs = _pack(a[i], tmpdata, string_cache);
|
||||
encode_uint32(ofs, &tmpdata[pos + 8 + i * 4]);
|
||||
encode_uint32(ofs, &tmpdata.write[pos + 8 + i * 4]);
|
||||
}
|
||||
|
||||
return pos;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue