You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-04 12:00:25 +00:00
Address remaining scoped storage regressions
- Accelerate common path used to check the storage scope for a given path - Update the logic for the `get_as_text()` method - previous logic loads the content of a text file one byte at a time
This commit is contained in:
@@ -30,6 +30,7 @@
|
||||
|
||||
#include "file_access_filesystem_jandroid.h"
|
||||
#include "core/os/os.h"
|
||||
#include "core/templates/local_vector.h"
|
||||
#include "thread_jandroid.h"
|
||||
#include <unistd.h>
|
||||
|
||||
@@ -166,6 +167,51 @@ uint8_t FileAccessFilesystemJAndroid::get_8() const {
|
||||
return byte;
|
||||
}
|
||||
|
||||
String FileAccessFilesystemJAndroid::get_line() const {
|
||||
ERR_FAIL_COND_V_MSG(!is_open(), String(), "File must be opened before use.");
|
||||
|
||||
const size_t buffer_size_limit = 2048;
|
||||
const uint64_t file_size = get_length();
|
||||
const uint64_t start_position = get_position();
|
||||
|
||||
String result;
|
||||
LocalVector<uint8_t> line_buffer;
|
||||
size_t current_buffer_size = 0;
|
||||
uint64_t line_buffer_position = 0;
|
||||
|
||||
while (true) {
|
||||
size_t line_buffer_size = MIN(buffer_size_limit, file_size - get_position());
|
||||
if (line_buffer_size <= 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
current_buffer_size += line_buffer_size;
|
||||
line_buffer.resize(current_buffer_size);
|
||||
|
||||
uint64_t bytes_read = get_buffer(&line_buffer[line_buffer_position], current_buffer_size - line_buffer_position);
|
||||
if (bytes_read <= 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
for (; bytes_read > 0; line_buffer_position++, bytes_read--) {
|
||||
uint8_t elem = line_buffer[line_buffer_position];
|
||||
if (elem == '\n' || elem == '\0') {
|
||||
// Found the end of the line
|
||||
const_cast<FileAccessFilesystemJAndroid *>(this)->seek(start_position + line_buffer_position + 1);
|
||||
if (result.parse_utf8((const char *)line_buffer.ptr(), line_buffer_position)) {
|
||||
return String();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (result.parse_utf8((const char *)line_buffer.ptr(), line_buffer_position)) {
|
||||
return String();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
uint64_t FileAccessFilesystemJAndroid::get_buffer(uint8_t *p_dst, uint64_t p_length) const {
|
||||
if (_file_read) {
|
||||
ERR_FAIL_COND_V_MSG(!is_open(), 0, "File must be opened before use.");
|
||||
|
||||
Reference in New Issue
Block a user