From e01c40ede5f7cb028587c3a7bf7863cc41d813f9 Mon Sep 17 00:00:00 2001 From: Ferdinand Majerech Date: Tue, 5 Aug 2014 20:36:33 +0200 Subject: [PATCH] Func to count consecutive ASCII chars starting at current Reader position. --- source/dyaml/reader.d | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/source/dyaml/reader.d b/source/dyaml/reader.d index 0ddb393..7a7a069 100644 --- a/source/dyaml/reader.d +++ b/source/dyaml/reader.d @@ -76,6 +76,11 @@ final class Reader Endian endian_; } + // The number of consecutive ASCII characters starting at bufferOffset_. + // + // Used to minimize UTF-8 decoding. + size_t upcomingASCII_ = 0; + // Index to buffer_ where the last decoded character starts. size_t lastDecodedBufferOffset_ = 0; // Offset, relative to charIndex_, of the last decoded character, @@ -320,6 +325,12 @@ final class Reader Encoding encoding() @safe pure nothrow const @nogc { return encoding_; } private: + // Update upcomingASCII_ (should be called forward()ing over a UTF-8 sequence) + void checkASCII() @safe pure nothrow @nogc + { + upcomingASCII_ = countASCII(buffer_[bufferOffset_ .. $]); + } + // Decode the next character relative to // lastDecodedCharOffset_/lastDecodedBufferOffset_ and update them. //