Skip to content

Commit

Permalink
Only update last accepted position when needed.
Browse files Browse the repository at this point in the history
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 369c0c5
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/strings/utf8.c
Expand Up @@ -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
Expand All @@ -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;
}

Expand All @@ -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
Expand Down

0 comments on commit 369c0c5

Please sign in to comment.