From a4befdd866b6b7dd4778804951585066b871dc51 Mon Sep 17 00:00:00 2001 From: Ferdinand Majerech Date: Mon, 4 Aug 2014 02:19:34 +0200 Subject: [PATCH] An optimized version of Reader.peek() with index == 0. --- source/dyaml/reader.d | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/source/dyaml/reader.d b/source/dyaml/reader.d index b9cf43d..4c24526 100644 --- a/source/dyaml/reader.d +++ b/source/dyaml/reader.d @@ -137,7 +137,7 @@ final class Reader /// // XXX removed; search for 'risky' to find why. // Throws: ReaderException if trying to read past the end of the buffer. - dchar peek(size_t index = 0) @safe pure nothrow @nogc + dchar peek(const size_t index) @safe pure nothrow @nogc { if(characterCount_ <= charIndex_ + index) { @@ -176,6 +176,16 @@ final class Reader return d; } + /// Optimized version of peek() for the case where peek index is 0. + dchar peek() @safe pure nothrow @nogc + { + if(characterCount_ <= charIndex_) { return '\0'; } + + lastDecodedCharOffset_ = 0; + lastDecodedBufferOffset_ = bufferOffset_; + return decodeNext(); + } + /// Get specified number of characters starting at current position. /// /// Note: This gets only a "view" into the internal buffer,