aboutsummaryrefslogtreecommitdiff
path: root/libbutl/char-scanner.ixx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2017-05-26 17:20:30 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2017-05-26 17:20:30 +0200
commit1b57e247b8d1a7a41a8ee45d6d524c71edd63a81 (patch)
treeb226e55b4ea9c2c4ecba286ac9e3dccf9d09292d /libbutl/char-scanner.ixx
parent4c4f3160258e799c65dccc80c00bb7ef16daac01 (diff)
Optimize char_scanner if used with ifdstream
Diffstat (limited to 'libbutl/char-scanner.ixx')
-rw-r--r--libbutl/char-scanner.ixx31
1 files changed, 31 insertions, 0 deletions
diff --git a/libbutl/char-scanner.ixx b/libbutl/char-scanner.ixx
index 2d96207..0e00dfd 100644
--- a/libbutl/char-scanner.ixx
+++ b/libbutl/char-scanner.ixx
@@ -29,4 +29,35 @@ namespace butl
unget_ = true;
ungetc_ = c;
}
+
+ inline auto char_scanner::
+ peek_ () -> int_type
+ {
+ if (gptr_ != egptr_)
+ return *gptr_;
+
+ int_type r (is_.peek ());
+
+ // Update buffer pointers for the next chunk.
+ //
+ if (buf_ != nullptr)
+ {
+ gptr_ = buf_->gptr ();
+ egptr_ = buf_->egptr ();
+ }
+
+ return r;
+ }
+
+ inline void char_scanner::
+ get_ ()
+ {
+ if (gptr_ != egptr_)
+ {
+ buf_->gbump (1);
+ ++gptr_;
+ }
+ else
+ is_.get (); // About as fast as ignore() and way faster than tellg().
+ }
}