You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-18 14:21:41 +00:00
Add readahead to VariantParser
Adds a readahead buffer to VariantParser, to prevent large numbers of freads for single bytes, which is inefficient.
This commit is contained in:
@@ -38,35 +38,50 @@
|
||||
class VariantParser {
|
||||
public:
|
||||
struct Stream {
|
||||
virtual CharType get_char() = 0;
|
||||
virtual bool is_utf8() const = 0;
|
||||
virtual bool is_eof() const = 0;
|
||||
private:
|
||||
enum { READAHEAD_SIZE = 2048 };
|
||||
CharType readahead_buffer[READAHEAD_SIZE];
|
||||
uint32_t readahead_pointer = 0;
|
||||
uint32_t readahead_filled = 0;
|
||||
bool eof = false;
|
||||
|
||||
protected:
|
||||
virtual uint32_t _read_buffer(CharType *p_buffer, uint32_t p_num_chars) = 0;
|
||||
|
||||
public:
|
||||
CharType saved;
|
||||
|
||||
CharType get_char();
|
||||
virtual bool is_utf8() const = 0;
|
||||
bool is_eof() const { return eof; }
|
||||
|
||||
Stream() :
|
||||
saved(0) {}
|
||||
virtual ~Stream() {}
|
||||
};
|
||||
|
||||
struct StreamFile : public Stream {
|
||||
protected:
|
||||
virtual uint32_t _read_buffer(CharType *p_buffer, uint32_t p_num_chars);
|
||||
|
||||
public:
|
||||
FileAccess *f;
|
||||
|
||||
virtual CharType get_char();
|
||||
virtual bool is_utf8() const;
|
||||
virtual bool is_eof() const;
|
||||
|
||||
StreamFile() { f = nullptr; }
|
||||
};
|
||||
|
||||
struct StreamString : public Stream {
|
||||
String s;
|
||||
private:
|
||||
int pos;
|
||||
|
||||
virtual CharType get_char();
|
||||
virtual bool is_utf8() const;
|
||||
virtual bool is_eof() const;
|
||||
protected:
|
||||
virtual uint32_t _read_buffer(CharType *p_buffer, uint32_t p_num_chars);
|
||||
|
||||
public:
|
||||
String s;
|
||||
|
||||
virtual bool is_utf8() const;
|
||||
StreamString() { pos = 0; }
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user