summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <remi@verschelde.fr>2022-07-22 00:22:30 +0200
committerGitHub <noreply@github.com>2022-07-22 00:22:30 +0200
commit9b782b75737f9a436f4cb4476743f014bca846e1 (patch)
treee7ae00ebda53cbd75f8a045505d8b4738b85d13e
parent74be36e622efd2cea912a2ad444fd045a0e79d1e (diff)
parent31712cc9e705e49e217fca98adae40e9bbda9846 (diff)
Merge pull request #63242 from m4gr3d/fix_slow_copy_main
Address slow copy performance when using the `FileAccessFilesystemJAndroid` implementation
-rw-r--r--core/io/dir_access.cpp17
1 files changed, 15 insertions, 2 deletions
diff --git a/core/io/dir_access.cpp b/core/io/dir_access.cpp
index 0a900078b7..f82d6f077f 100644
--- a/core/io/dir_access.cpp
+++ b/core/io/dir_access.cpp
@@ -34,6 +34,7 @@
#include "core/io/file_access.h"
#include "core/os/memory.h"
#include "core/os/os.h"
+#include "core/templates/local_vector.h"
String DirAccess::_get_root_path() const {
switch (_access_type) {
@@ -286,11 +287,16 @@ Error DirAccess::copy(String p_from, String p_to, int p_chmod_flags) {
Ref<FileAccess> fdst = FileAccess::open(p_to, FileAccess::WRITE, &err);
ERR_FAIL_COND_V_MSG(err != OK, err, "Failed to open " + p_to);
+ 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;
@@ -300,7 +306,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;
}
}