Skip to content

Commit

Permalink
Merge pull request #63223 from m4gr3d/fix_slow_copy_3x
Browse files Browse the repository at this point in the history
[3.x] Address slow copy performance when using the `FileAccessFilesystemJAndroid` implementation
  • Loading branch information
akien-mga authored Jul 21, 2022
2 parents b33d3d6 + aab26ad commit c8099e9
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions core/os/dir_access.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,11 +298,16 @@ Error DirAccess::copy(String p_from, String p_to, int p_chmod_flags) {
return err;
}

const size_t copy_buffer_limit = 65536; // 64 KB

fsrc->seek_end(0);
int size = fsrc->get_position();
fsrc->seek(0);
err = OK;
while (size--) {
size_t buffer_size = MIN(size * sizeof(uint8_t), copy_buffer_limit);
LocalVector<uint8_t> buffer;
buffer.resize(buffer_size);
while (size > 0) {
if (fsrc->get_error() != OK) {
err = fsrc->get_error();
break;
Expand All @@ -312,7 +317,14 @@ Error DirAccess::copy(String p_from, String p_to, int p_chmod_flags) {
break;
}

fdst->store_8(fsrc->get_8());
int bytes_read = fsrc->get_buffer(buffer.ptr(), buffer_size);
if (bytes_read <= 0) {
err = FAILED;
break;
}
fdst->store_buffer(buffer.ptr(), bytes_read);

size -= bytes_read;
}

if (err == OK && p_chmod_flags != -1) {
Expand Down

0 comments on commit c8099e9

Please sign in to comment.