Fast path ASCII in unicode decode.

In the case of ASCII characters, which a lot of WGSL source is, the
decoder can early out after a checking the value.

Change-Id: Iff655565dde23b143fddb95c6c353a917e25e916
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/128120
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
dan sinclair 2023-04-22 01:04:40 +00:00 committed by Dawn LUCI CQ
parent 89c89b7640
commit 9b726858ff
1 changed files with 4 additions and 0 deletions

View File

@ -336,6 +336,10 @@ std::pair<CodePoint, size_t> Decode(const uint8_t* ptr, size_t len) {
if (len < 1) {
return {};
}
// Fast-path ASCII characters as they're always valid
if (ptr[0] <= 0x7f) {
return {CodePoint{ptr[0]}, 1};
}
// Lookup table for the first byte of a UTF-8 sequence.
// 0 indicates an invalid length.