From 3b35d1347da4e1807e76e5d61eab14be7de28ffd Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 11 Dec 2011 09:34:26 +0000 Subject: Improve write performance by doing bulk writes for unescaped substrings. git-svn-id: http://svn.drobilla.net/serd/trunk@238 490d8e77-9747-427b-9fa3-0b8f29cee8a0 --- src/writer.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src') diff --git a/src/writer.c b/src/writer.c index a3cb5eab..8ab533d4 100644 --- a/src/writer.c +++ b/src/writer.c @@ -69,6 +69,22 @@ write_text(SerdWriter* writer, TextContext ctx, { char escape[11] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; for (size_t i = 0; i < n_bytes;) { + // Fast bulk write for long strings of printable ASCII + size_t j = i; + for (; j < n_bytes; ++j) { + if (utf8[j] == terminator || utf8[j] == '\\' + || (((writer->style & SERD_STYLE_ASCII) || ctx == WRITE_URI) + && !in_range(utf8[j], 0x20, 0x7E))) { + break; + } + } + + if (j > i) { + writer->sink(&utf8[i], j - i, writer->stream); + i = j; + continue; + } + uint8_t in = utf8[i++]; if (ctx == WRITE_LONG_STRING) { if (in == '\\') { -- cgit v1.2.1