Commit 184dab60 authored by Perry Kundert's avatar Perry Kundert

Accelerate access to underlying std::istream streambuf

parent f775922c
...@@ -1417,6 +1417,7 @@ class input_stream_adapter : public input_adapter_protocol ...@@ -1417,6 +1417,7 @@ class input_stream_adapter : public input_adapter_protocol
} }
explicit input_stream_adapter(std::istream& i) explicit input_stream_adapter(std::istream& i)
: is(i) : is(i)
, sb(i.rdbuf())
{ {
// Ignore Byte Order Mark at start of input // Ignore Byte Order Mark at start of input
int c; int c;
...@@ -1448,18 +1449,19 @@ class input_stream_adapter : public input_adapter_protocol ...@@ -1448,18 +1449,19 @@ class input_stream_adapter : public input_adapter_protocol
int get_character() override int get_character() override
{ {
int c = is.rdbuf()->sbumpc(); // Avoided for performance: int c = is.get(); int c = sb->sbumpc(); // Avoided for performance: int c = is.get();
return c < 0 ? c : ( c & 0xFF ); // faster than == std::char_traits<char>::eof() return c < 0 ? c : ( c & 0xFF ); // faster than == std::char_traits<char>::eof()
} }
void unget_character() override void unget_character() override
{ {
is.rdbuf()->sungetc(); // Avoided for performance: is.unget(); sb->sungetc(); // Avoided for performance: is.unget();
} }
private: private:
/// the associated input stream /// the associated input stream
std::istream& is; std::istream& is;
std::streambuf *sb;
}; };
/// input adapter for buffer input /// input adapter for buffer input
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment