diff options
author | David Robillard <d@drobilla.net> | 2011-12-11 09:34:26 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2011-12-11 09:34:26 +0000 |
commit | 3b35d1347da4e1807e76e5d61eab14be7de28ffd (patch) | |
tree | ac09b48197bb36562dd592d7548b11f0948abda9 | |
parent | 7a650f12ff560dcb3a0cdbbf425992a424b043ce (diff) | |
download | serd-3b35d1347da4e1807e76e5d61eab14be7de28ffd.tar.gz serd-3b35d1347da4e1807e76e5d61eab14be7de28ffd.tar.bz2 serd-3b35d1347da4e1807e76e5d61eab14be7de28ffd.zip |
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
-rw-r--r-- | ChangeLog | 1 | ||||
-rw-r--r-- | src/writer.c | 16 |
2 files changed, 17 insertions, 0 deletions
@@ -5,6 +5,7 @@ serd (UNRELEASED) unstable; urgency=low * Tolerate invalid characters in string literals by replacing with the Unicode replacement character * Report reason for failure to open file in serdi + * Improve write performance by doing bulk writes for unescaped substrings -- David Robillard <d@drobilla.net> (UNRELEASED) 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 == '\\') { |