summaryrefslogtreecommitdiff
path: root/core/variant/variant_parser.cpp
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2022-12-12 17:30:16 +0100
committerRémi Verschelde <rverschelde@gmail.com>2022-12-12 17:30:16 +0100
commitba4bd7f00971a94c20d90e7d2c665d5eb0ae1b90 (patch)
tree0fa58e29f475274ba149e38290f3c9b027f37dec /core/variant/variant_parser.cpp
parent8ab653c7eaebcbf404c203152c855fa2f15a2517 (diff)
parent491594ef0f56dcafd9a1aaba7b66ec23c9f18af4 (diff)
Merge pull request #69961 from lawnjelly/variant_parser_optional_readahead
VariantParser make readahead optional
Diffstat (limited to 'core/variant/variant_parser.cpp')
-rw-r--r--core/variant/variant_parser.cpp17
1 files changed, 16 insertions, 1 deletions
diff --git a/core/variant/variant_parser.cpp b/core/variant/variant_parser.cpp
index 9f500dbf5e..f122ed5f8f 100644
--- a/core/variant/variant_parser.cpp
+++ b/core/variant/variant_parser.cpp
@@ -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);