You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-10 13:00:37 +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:
@@ -89,7 +89,7 @@ Error FileAccessEncrypted::open_and_parse(FileAccess *p_base, const Vector<uint8
|
||||
|
||||
for (size_t i = 0; i < ds; i += 16) {
|
||||
|
||||
aes256_decrypt_ecb(&ctx, &data[i]);
|
||||
aes256_decrypt_ecb(&ctx, &data.write[i]);
|
||||
}
|
||||
|
||||
aes256_done(&ctx);
|
||||
@@ -117,7 +117,7 @@ Error FileAccessEncrypted::open_and_parse_password(FileAccess *p_base, const Str
|
||||
key.resize(32);
|
||||
for (int i = 0; i < 32; i++) {
|
||||
|
||||
key[i] = cs[i];
|
||||
key.write[i] = cs[i];
|
||||
}
|
||||
|
||||
return open_and_parse(p_base, key, p_mode);
|
||||
@@ -148,7 +148,7 @@ void FileAccessEncrypted::close() {
|
||||
compressed.resize(len);
|
||||
zeromem(compressed.ptrw(), len);
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
compressed[i] = data[i];
|
||||
compressed.write[i] = data[i];
|
||||
}
|
||||
|
||||
aes256_context ctx;
|
||||
@@ -156,7 +156,7 @@ void FileAccessEncrypted::close() {
|
||||
|
||||
for (size_t i = 0; i < len; i += 16) {
|
||||
|
||||
aes256_encrypt_ecb(&ctx, &compressed[i]);
|
||||
aes256_encrypt_ecb(&ctx, &compressed.write[i]);
|
||||
}
|
||||
|
||||
aes256_done(&ctx);
|
||||
@@ -263,7 +263,7 @@ void FileAccessEncrypted::store_buffer(const uint8_t *p_src, int p_length) {
|
||||
data.resize(pos + p_length);
|
||||
for (int i = 0; i < p_length; i++) {
|
||||
|
||||
data[pos + i] = p_src[i];
|
||||
data.write[pos + i] = p_src[i];
|
||||
}
|
||||
pos += p_length;
|
||||
}
|
||||
@@ -280,7 +280,7 @@ void FileAccessEncrypted::store_8(uint8_t p_dest) {
|
||||
ERR_FAIL_COND(!writing);
|
||||
|
||||
if (pos < data.size()) {
|
||||
data[pos] = p_dest;
|
||||
data.write[pos] = p_dest;
|
||||
pos++;
|
||||
} else if (pos == data.size()) {
|
||||
data.push_back(p_dest);
|
||||
|
||||
Reference in New Issue
Block a user