mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2025-02-02 14:25:55 +01:00
Address slow copy performance when using the FileAccessFilesystemJAndroid
implementation.
Read/write ops for this implementation are done through the java layer via jni, and so for good performance, it's key to avoid numerous repeated small read/write ops due the jni overhead. The alternative is to allocate a (conversatively-sized) large buffer to reduce the number of read/write ops over the jni boundary.
This commit is contained in:
parent
561314ee93
commit
361b5b23f7
@ -298,11 +298,16 @@ Error DirAccess::copy(String p_from, String p_to, int p_chmod_flags) {
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const size_t copy_buffer_limit = 65536; // 64 KB
|
||||||
|
|
||||||
fsrc->seek_end(0);
|
fsrc->seek_end(0);
|
||||||
int size = fsrc->get_position();
|
int size = fsrc->get_position();
|
||||||
fsrc->seek(0);
|
fsrc->seek(0);
|
||||||
err = OK;
|
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) {
|
if (fsrc->get_error() != OK) {
|
||||||
err = fsrc->get_error();
|
err = fsrc->get_error();
|
||||||
break;
|
break;
|
||||||
@ -312,7 +317,14 @@ Error DirAccess::copy(String p_from, String p_to, int p_chmod_flags) {
|
|||||||
break;
|
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) {
|
if (err == OK && p_chmod_flags != -1) {
|
||||||
|
Loading…
Reference in New Issue
Block a user