Permalink
Browse files

Only update last accepted position when needed.

Saves a bunch of writes during the UTF-8 hot loop. Saves another 180
million instructions, or 2 per character decoded in the fast path.
  • Loading branch information...
jnthn committed Jun 16, 2017
1 parent b885d99 commit 369c0c5ca6f45aafcaa43e4d4cc03c5d7b8e4231
Showing with 6 additions and 2 deletions.
  1. +6 −2 src/strings/utf8.c
View
@@ -415,8 +415,6 @@ MVMuint32 MVM_string_utf8_decodestream(MVMThreadContext *tc, MVMDecodeStream *ds
/* As we have a lagging codepoint, and this one does not
* need normalization, then we know we can spit out the
* lagging one. */
last_accept_bytes = lag_last_accept_bytes;
last_accept_pos = lag_last_accept_pos;
if (count == bufsize) {
/* Valid character, but we filled the buffer. Attach this
* one to the buffers linked list, and continue with a new
@@ -429,10 +427,14 @@ MVMuint32 MVM_string_utf8_decodestream(MVMThreadContext *tc, MVMDecodeStream *ds
total++;
if (MVM_string_decode_stream_maybe_sep(tc, seps, lag_codepoint)) {
reached_stopper = 1;
last_accept_bytes = lag_last_accept_bytes;
last_accept_pos = lag_last_accept_pos;
goto done;
}
else if (stopper_chars && *stopper_chars == total) {
reached_stopper = 1;
last_accept_bytes = lag_last_accept_bytes;
last_accept_pos = lag_last_accept_pos;
goto done;
}
@@ -447,6 +449,8 @@ MVMuint32 MVM_string_utf8_decodestream(MVMThreadContext *tc, MVMDecodeStream *ds
break;
}
}
lag_last_accept_bytes = cur_bytes;
lag_last_accept_pos = pos;
/* If we fall out of the loop and have a lagged codepoint, but
* no next buffer, then we fall into the slow path to process it

0 comments on commit 369c0c5

Please sign in to comment.