1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-04 12:00:25 +00:00

Optimize data flushing for FileAccessCompressed and FileAccessEncrypted

This commit is contained in:
BlueCube3310
2025-09-01 18:29:01 +02:00
parent 76dfc53dee
commit ebdf57fbf1
2 changed files with 18 additions and 17 deletions

View File

@@ -130,34 +130,37 @@ void FileAccessCompressed::_close() {
f->store_32(0); //compressed sizes, will update later
}
Vector<int> block_sizes;
uint32_t last_block_size = write_max % block_size;
// Temporary buffer for compressed data blocks.
LocalVector<uint8_t> temp_cblock;
temp_cblock.resize(Compression::get_max_compressed_buffer_size(bc == 1 ? last_block_size : block_size, cmode));
uint8_t *temp_cblock_ptr = temp_cblock.ptr();
// Compress and store the blocks.
LocalVector<uint32_t> block_sizes;
for (uint32_t i = 0; i < bc; i++) {
uint32_t bl = i == (bc - 1) ? write_max % block_size : block_size;
uint32_t bl = i == (bc - 1) ? last_block_size : block_size;
uint8_t *bp = &write_ptr[i * block_size];
Vector<uint8_t> cblock;
cblock.resize(Compression::get_max_compressed_buffer_size(bl, cmode));
const int64_t compressed_size = Compression::compress(cblock.ptrw(), bp, bl, cmode);
const int64_t compressed_size = Compression::compress(temp_cblock_ptr, bp, bl, cmode);
ERR_FAIL_COND_MSG(compressed_size < 0, "FileAccessCompressed: Error compressing data.");
f->store_buffer(cblock.ptr(), (uint64_t)compressed_size);
f->store_buffer(temp_cblock_ptr, (uint64_t)compressed_size);
block_sizes.push_back(compressed_size);
}
f->seek(16); //ok write block sizes
for (uint32_t i = 0; i < bc; i++) {
f->store_32(uint32_t(block_sizes[i]));
f->store_32(block_sizes[i]);
}
f->seek_end();
f->store_buffer((const uint8_t *)mgc.get_data(), mgc.length()); //magic at the end too
buffer.clear();
} else {
comp_buffer.clear();
buffer.clear();
read_blocks.clear();
}
buffer.clear();
f.unref();
}