aboutsummaryrefslogtreecommitdiffstats
path: root/src/writer.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2011-12-11 09:34:26 +0000
committerDavid Robillard <d@drobilla.net>2011-12-11 09:34:26 +0000
commit3b35d1347da4e1807e76e5d61eab14be7de28ffd (patch)
treeac09b48197bb36562dd592d7548b11f0948abda9 /src/writer.c
parent7a650f12ff560dcb3a0cdbbf425992a424b043ce (diff)
downloadserd-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
Diffstat (limited to 'src/writer.c')
-rw-r--r--src/writer.c16
1 files changed, 16 insertions, 0 deletions
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 == '\\') {