You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-10 13:00:37 +00:00
VariantParser make readahead optional
It turns out some areas are independently moving / reading filepointers outside of the VariantParser, which can cause the readahead caching to get out of sync. This PR makes the VariantParser readahead to be optional to allow for these use cases.
This commit is contained in:
@@ -42,7 +42,7 @@ char32_t VariantParser::Stream::get_char() {
|
||||
}
|
||||
|
||||
// attempt to readahead
|
||||
readahead_filled = _read_buffer(readahead_buffer, READAHEAD_SIZE);
|
||||
readahead_filled = _read_buffer(readahead_buffer, readahead_enabled ? READAHEAD_SIZE : 1);
|
||||
if (readahead_filled) {
|
||||
readahead_pointer = 0;
|
||||
} else {
|
||||
@@ -54,10 +54,21 @@ char32_t VariantParser::Stream::get_char() {
|
||||
return get_char();
|
||||
}
|
||||
|
||||
bool VariantParser::Stream::is_eof() const {
|
||||
if (readahead_enabled) {
|
||||
return eof;
|
||||
}
|
||||
return _is_eof();
|
||||
}
|
||||
|
||||
bool VariantParser::StreamFile::is_utf8() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool VariantParser::StreamFile::_is_eof() const {
|
||||
return f->eof_reached();
|
||||
}
|
||||
|
||||
uint32_t VariantParser::StreamFile::_read_buffer(char32_t *p_buffer, uint32_t p_num_chars) {
|
||||
// The buffer is assumed to include at least one character (for null terminator)
|
||||
ERR_FAIL_COND_V(!p_num_chars, 0);
|
||||
@@ -79,6 +90,10 @@ bool VariantParser::StreamString::is_utf8() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool VariantParser::StreamString::_is_eof() const {
|
||||
return pos > s.length();
|
||||
}
|
||||
|
||||
uint32_t VariantParser::StreamString::_read_buffer(char32_t *p_buffer, uint32_t p_num_chars) {
|
||||
// The buffer is assumed to include at least one character (for null terminator)
|
||||
ERR_FAIL_COND_V(!p_num_chars, 0);
|
||||
|
||||
Reference in New Issue
Block a user