From 184dab60e6440092674d92e855cdcd2d51e175e0 Mon Sep 17 00:00:00 2001 From: Perry Kundert Date: Thu, 5 Oct 2017 14:13:55 -0700 Subject: [PATCH] Accelerate access to underlying std::istream streambuf --- src/json.hpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/json.hpp b/src/json.hpp index bf07d1c8..8f28051a 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -1417,6 +1417,7 @@ class input_stream_adapter : public input_adapter_protocol } explicit input_stream_adapter(std::istream& i) : is(i) + , sb(i.rdbuf()) { // Ignore Byte Order Mark at start of input int c; @@ -1448,18 +1449,19 @@ class input_stream_adapter : public input_adapter_protocol 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::eof() } void unget_character() override { - is.rdbuf()->sungetc(); // Avoided for performance: is.unget(); + sb->sungetc(); // Avoided for performance: is.unget(); } private: /// the associated input stream std::istream& is; + std::streambuf *sb; }; /// input adapter for buffer input