You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-09 12:50:35 +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:
@@ -301,37 +301,37 @@ Vector<uint8_t> AppxPackager::make_file_header(FileMeta p_file_meta) {
|
||||
|
||||
int offs = 0;
|
||||
// Write magic
|
||||
offs += buf_put_int32(FILE_HEADER_MAGIC, &buf[offs]);
|
||||
offs += buf_put_int32(FILE_HEADER_MAGIC, &buf.write[offs]);
|
||||
|
||||
// Version
|
||||
offs += buf_put_int16(ZIP_VERSION, &buf[offs]);
|
||||
offs += buf_put_int16(ZIP_VERSION, &buf.write[offs]);
|
||||
|
||||
// Special flag
|
||||
offs += buf_put_int16(GENERAL_PURPOSE, &buf[offs]);
|
||||
offs += buf_put_int16(GENERAL_PURPOSE, &buf.write[offs]);
|
||||
|
||||
// Compression
|
||||
offs += buf_put_int16(p_file_meta.compressed ? Z_DEFLATED : 0, &buf[offs]);
|
||||
offs += buf_put_int16(p_file_meta.compressed ? Z_DEFLATED : 0, &buf.write[offs]);
|
||||
|
||||
// File date and time
|
||||
offs += buf_put_int32(0, &buf[offs]);
|
||||
offs += buf_put_int32(0, &buf.write[offs]);
|
||||
|
||||
// CRC-32
|
||||
offs += buf_put_int32(p_file_meta.file_crc32, &buf[offs]);
|
||||
offs += buf_put_int32(p_file_meta.file_crc32, &buf.write[offs]);
|
||||
|
||||
// Compressed size
|
||||
offs += buf_put_int32(p_file_meta.compressed_size, &buf[offs]);
|
||||
offs += buf_put_int32(p_file_meta.compressed_size, &buf.write[offs]);
|
||||
|
||||
// Uncompressed size
|
||||
offs += buf_put_int32(p_file_meta.uncompressed_size, &buf[offs]);
|
||||
offs += buf_put_int32(p_file_meta.uncompressed_size, &buf.write[offs]);
|
||||
|
||||
// File name length
|
||||
offs += buf_put_int16(p_file_meta.name.length(), &buf[offs]);
|
||||
offs += buf_put_int16(p_file_meta.name.length(), &buf.write[offs]);
|
||||
|
||||
// Extra data length
|
||||
offs += buf_put_int16(0, &buf[offs]);
|
||||
offs += buf_put_int16(0, &buf.write[offs]);
|
||||
|
||||
// File name
|
||||
offs += buf_put_string(p_file_meta.name, &buf[offs]);
|
||||
offs += buf_put_string(p_file_meta.name, &buf.write[offs]);
|
||||
|
||||
// Done!
|
||||
return buf;
|
||||
@@ -344,47 +344,47 @@ void AppxPackager::store_central_dir_header(const FileMeta &p_file, bool p_do_ha
|
||||
buf.resize(buf.size() + BASE_CENTRAL_DIR_SIZE + p_file.name.length());
|
||||
|
||||
// Write magic
|
||||
offs += buf_put_int32(CENTRAL_DIR_MAGIC, &buf[offs]);
|
||||
offs += buf_put_int32(CENTRAL_DIR_MAGIC, &buf.write[offs]);
|
||||
|
||||
// ZIP versions
|
||||
offs += buf_put_int16(ZIP_ARCHIVE_VERSION, &buf[offs]);
|
||||
offs += buf_put_int16(ZIP_VERSION, &buf[offs]);
|
||||
offs += buf_put_int16(ZIP_ARCHIVE_VERSION, &buf.write[offs]);
|
||||
offs += buf_put_int16(ZIP_VERSION, &buf.write[offs]);
|
||||
|
||||
// General purpose flag
|
||||
offs += buf_put_int16(GENERAL_PURPOSE, &buf[offs]);
|
||||
offs += buf_put_int16(GENERAL_PURPOSE, &buf.write[offs]);
|
||||
|
||||
// Compression
|
||||
offs += buf_put_int16(p_file.compressed ? Z_DEFLATED : 0, &buf[offs]);
|
||||
offs += buf_put_int16(p_file.compressed ? Z_DEFLATED : 0, &buf.write[offs]);
|
||||
|
||||
// Modification date/time
|
||||
offs += buf_put_int32(0, &buf[offs]);
|
||||
offs += buf_put_int32(0, &buf.write[offs]);
|
||||
|
||||
// Crc-32
|
||||
offs += buf_put_int32(p_file.file_crc32, &buf[offs]);
|
||||
offs += buf_put_int32(p_file.file_crc32, &buf.write[offs]);
|
||||
|
||||
// File sizes
|
||||
offs += buf_put_int32(p_file.compressed_size, &buf[offs]);
|
||||
offs += buf_put_int32(p_file.uncompressed_size, &buf[offs]);
|
||||
offs += buf_put_int32(p_file.compressed_size, &buf.write[offs]);
|
||||
offs += buf_put_int32(p_file.uncompressed_size, &buf.write[offs]);
|
||||
|
||||
// File name length
|
||||
offs += buf_put_int16(p_file.name.length(), &buf[offs]);
|
||||
offs += buf_put_int16(p_file.name.length(), &buf.write[offs]);
|
||||
|
||||
// Extra field length
|
||||
offs += buf_put_int16(0, &buf[offs]);
|
||||
offs += buf_put_int16(0, &buf.write[offs]);
|
||||
|
||||
// Comment length
|
||||
offs += buf_put_int16(0, &buf[offs]);
|
||||
offs += buf_put_int16(0, &buf.write[offs]);
|
||||
|
||||
// Disk number start, internal/external file attributes
|
||||
for (int i = 0; i < 8; i++) {
|
||||
buf[offs++] = 0;
|
||||
buf.write[offs++] = 0;
|
||||
}
|
||||
|
||||
// Relative offset
|
||||
offs += buf_put_int32(p_file.zip_offset, &buf[offs]);
|
||||
offs += buf_put_int32(p_file.zip_offset, &buf.write[offs]);
|
||||
|
||||
// File name
|
||||
offs += buf_put_string(p_file.name, &buf[offs]);
|
||||
offs += buf_put_string(p_file.name, &buf.write[offs]);
|
||||
|
||||
// Done!
|
||||
}
|
||||
@@ -397,62 +397,62 @@ Vector<uint8_t> AppxPackager::make_end_of_central_record() {
|
||||
int offs = 0;
|
||||
|
||||
// Write magic
|
||||
offs += buf_put_int32(ZIP64_END_OF_CENTRAL_DIR_MAGIC, &buf[offs]);
|
||||
offs += buf_put_int32(ZIP64_END_OF_CENTRAL_DIR_MAGIC, &buf.write[offs]);
|
||||
|
||||
// Size of this record
|
||||
offs += buf_put_int64(ZIP64_END_OF_CENTRAL_DIR_SIZE, &buf[offs]);
|
||||
offs += buf_put_int64(ZIP64_END_OF_CENTRAL_DIR_SIZE, &buf.write[offs]);
|
||||
|
||||
// Version (yes, twice)
|
||||
offs += buf_put_int16(ZIP_ARCHIVE_VERSION, &buf[offs]);
|
||||
offs += buf_put_int16(ZIP_ARCHIVE_VERSION, &buf[offs]);
|
||||
offs += buf_put_int16(ZIP_ARCHIVE_VERSION, &buf.write[offs]);
|
||||
offs += buf_put_int16(ZIP_ARCHIVE_VERSION, &buf.write[offs]);
|
||||
|
||||
// Disk number
|
||||
for (int i = 0; i < 8; i++) {
|
||||
buf[offs++] = 0;
|
||||
buf.write[offs++] = 0;
|
||||
}
|
||||
|
||||
// Number of entries (total and per disk)
|
||||
offs += buf_put_int64(file_metadata.size(), &buf[offs]);
|
||||
offs += buf_put_int64(file_metadata.size(), &buf[offs]);
|
||||
offs += buf_put_int64(file_metadata.size(), &buf.write[offs]);
|
||||
offs += buf_put_int64(file_metadata.size(), &buf.write[offs]);
|
||||
|
||||
// Size of central dir
|
||||
offs += buf_put_int64(central_dir_data.size(), &buf[offs]);
|
||||
offs += buf_put_int64(central_dir_data.size(), &buf.write[offs]);
|
||||
|
||||
// Central dir offset
|
||||
offs += buf_put_int64(central_dir_offset, &buf[offs]);
|
||||
offs += buf_put_int64(central_dir_offset, &buf.write[offs]);
|
||||
|
||||
////// ZIP64 locator
|
||||
|
||||
// Write magic for zip64 central dir locator
|
||||
offs += buf_put_int32(ZIP64_END_DIR_LOCATOR_MAGIC, &buf[offs]);
|
||||
offs += buf_put_int32(ZIP64_END_DIR_LOCATOR_MAGIC, &buf.write[offs]);
|
||||
|
||||
// Disk number
|
||||
for (int i = 0; i < 4; i++) {
|
||||
buf[offs++] = 0;
|
||||
buf.write[offs++] = 0;
|
||||
}
|
||||
|
||||
// Relative offset
|
||||
offs += buf_put_int64(end_of_central_dir_offset, &buf[offs]);
|
||||
offs += buf_put_int64(end_of_central_dir_offset, &buf.write[offs]);
|
||||
|
||||
// Number of disks
|
||||
offs += buf_put_int32(1, &buf[offs]);
|
||||
offs += buf_put_int32(1, &buf.write[offs]);
|
||||
|
||||
/////// End of zip directory
|
||||
|
||||
// Write magic for end central dir
|
||||
offs += buf_put_int32(END_OF_CENTRAL_DIR_MAGIC, &buf[offs]);
|
||||
offs += buf_put_int32(END_OF_CENTRAL_DIR_MAGIC, &buf.write[offs]);
|
||||
|
||||
// Dummy stuff for Zip64
|
||||
for (int i = 0; i < 4; i++) {
|
||||
buf[offs++] = 0x0;
|
||||
buf.write[offs++] = 0x0;
|
||||
}
|
||||
for (int i = 0; i < 12; i++) {
|
||||
buf[offs++] = 0xFF;
|
||||
buf.write[offs++] = 0xFF;
|
||||
}
|
||||
|
||||
// Size of comments
|
||||
for (int i = 0; i < 2; i++) {
|
||||
buf[offs++] = 0;
|
||||
buf.write[offs++] = 0;
|
||||
}
|
||||
|
||||
// Done!
|
||||
@@ -508,7 +508,7 @@ void AppxPackager::add_file(String p_file_name, const uint8_t *p_buffer, size_t
|
||||
size_t block_size = (p_len - step) > BLOCK_SIZE ? BLOCK_SIZE : (p_len - step);
|
||||
|
||||
for (uint32_t i = 0; i < block_size; i++) {
|
||||
strm_in[i] = p_buffer[step + i];
|
||||
strm_in.write[i] = p_buffer[step + i];
|
||||
}
|
||||
|
||||
BlockHash bh;
|
||||
@@ -530,14 +530,14 @@ void AppxPackager::add_file(String p_file_name, const uint8_t *p_buffer, size_t
|
||||
int start = file_buffer.size();
|
||||
file_buffer.resize(file_buffer.size() + bh.compressed_size);
|
||||
for (uint32_t i = 0; i < bh.compressed_size; i++)
|
||||
file_buffer[start + i] = strm_out[i];
|
||||
file_buffer.write[start + i] = strm_out[i];
|
||||
} else {
|
||||
bh.compressed_size = block_size;
|
||||
//package->store_buffer(strm_in.ptr(), block_size);
|
||||
int start = file_buffer.size();
|
||||
file_buffer.resize(file_buffer.size() + block_size);
|
||||
for (uint32_t i = 0; i < bh.compressed_size; i++)
|
||||
file_buffer[start + i] = strm_in[i];
|
||||
file_buffer.write[start + i] = strm_in[i];
|
||||
}
|
||||
|
||||
meta.hashes.push_back(bh);
|
||||
@@ -560,7 +560,7 @@ void AppxPackager::add_file(String p_file_name, const uint8_t *p_buffer, size_t
|
||||
int start = file_buffer.size();
|
||||
file_buffer.resize(file_buffer.size() + (strm.total_out - total_out_before));
|
||||
for (uint32_t i = 0; i < (strm.total_out - total_out_before); i++)
|
||||
file_buffer[start + i] = strm_out[i];
|
||||
file_buffer.write[start + i] = strm_out[i];
|
||||
|
||||
deflateEnd(&strm);
|
||||
meta.compressed_size = strm.total_out;
|
||||
@@ -864,7 +864,7 @@ class EditorExportUWP : public EditorExportPlatform {
|
||||
r_ret.resize(result.length());
|
||||
|
||||
for (int i = 0; i < result.length(); i++)
|
||||
r_ret[i] = result.utf8().get(i);
|
||||
r_ret.write[i] = result.utf8().get(i);
|
||||
|
||||
return r_ret;
|
||||
}
|
||||
@@ -1371,8 +1371,8 @@ public:
|
||||
CharString txt = cl[i].utf8();
|
||||
int base = clf.size();
|
||||
clf.resize(base + 4 + txt.length());
|
||||
encode_uint32(txt.length(), &clf[base]);
|
||||
copymem(&clf[base + 4], txt.ptr(), txt.length());
|
||||
encode_uint32(txt.length(), &clf.write[base]);
|
||||
copymem(&clf.write[base + 4], txt.ptr(), txt.length());
|
||||
print_line(itos(i) + " param: " + cl[i]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user