From 1b57e247b8d1a7a41a8ee45d6d524c71edd63a81 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 26 May 2017 17:20:30 +0200 Subject: Optimize char_scanner if used with ifdstream --- libbutl/char-scanner.hxx | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) (limited to 'libbutl/char-scanner.hxx') diff --git a/libbutl/char-scanner.hxx b/libbutl/char-scanner.hxx index e71f286..80a1f2a 100644 --- a/libbutl/char-scanner.hxx +++ b/libbutl/char-scanner.hxx @@ -6,8 +6,10 @@ #define LIBBUTL_CHAR_SCANNER_HXX #include // char_traits -#include #include // uint64_t +#include + +#include #include @@ -23,8 +25,11 @@ namespace butl // 0x0A) and convert them to just '\n' (0x0A). Note that a standalone // 0x0D is treated "as if" it was followed by 0x0A. // - char_scanner (std::istream& is, bool crlf = true) - : is_ (is), crlf_ (crlf) {} + // Note also that if the stream happens to be ifdstream, then it includes + // a number of optimizations that assume nobody else is messing with the + // stream. + // + char_scanner (std::istream& is, bool crlf = true); char_scanner (const char_scanner&) = delete; char_scanner& operator= (const char_scanner&) = delete; @@ -43,9 +48,9 @@ namespace butl class xchar { public: - typedef std::char_traits traits_type; - typedef traits_type::int_type int_type; - typedef traits_type::char_type char_type; + using traits_type = std::char_traits; + using int_type = traits_type::int_type; + using char_type = traits_type::char_type; int_type value; std::uint64_t line; @@ -90,8 +95,22 @@ namespace butl std::uint64_t column = 1; protected: + using int_type = xchar::int_type; + using char_type = xchar::char_type; + + int_type + peek_ (); + + void + get_ (); + + protected: std::istream& is_; + fdbuf* buf_; // NULL if not ifdstream. + const char_type* gptr_; + const char_type* egptr_; + bool crlf_; bool eos_ = false; -- cgit v1.1