From 47681c79c8bbc8ace565c19e1f21d8d45c96c851 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Sinan=20A=C4=9Facan?= Date: Mon, 18 Nov 2024 13:30:17 +0000 Subject: [PATCH] [dart2wasm] Simplify UTF-8 decoder flag scanning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Simplify the VM-specific `scan` function that assumes an instruction called `Utf8ScanInstr` and scans the input in chunks to be able to use the instruction. Instead scan the whole input in one loop. Change-Id: I9c796e0728e46687653b623effb214ebc93cc01c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/395960 Commit-Queue: Ömer Ağacan Reviewed-by: Martin Kustermann --- sdk/lib/_internal/wasm/lib/convert_patch.dart | 21 ------------------- 1 file changed, 21 deletions(-) diff --git a/sdk/lib/_internal/wasm/lib/convert_patch.dart b/sdk/lib/_internal/wasm/lib/convert_patch.dart index eff0229acf7..dff3eae115d 100644 --- a/sdk/lib/_internal/wasm/lib/convert_patch.dart +++ b/sdk/lib/_internal/wasm/lib/convert_patch.dart @@ -1980,13 +1980,6 @@ class _Utf8Decoder { 82, 82, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, ]); - /// Max chunk to scan at a time. - /// - /// Avoids staying away from safepoints too long. - /// The Utf8ScanInstr relies on this being small enough to ensure the - /// decoded length stays within Smi range. - static const int scanChunkSize = 65536; - /// Reset the decoder to a state where it is ready to decode a new string but /// will not skip a leading BOM. Used by the fused UTF-8 / JSON decoder. void reset() { @@ -1995,20 +1988,6 @@ class _Utf8Decoder { } int scan(Uint8List bytes, int start, int end) { - // Assumes 0 <= start <= end <= bytes.length - int size = 0; - _scanFlags = 0; - int localStart = start; - while (end - localStart > scanChunkSize) { - int localEnd = localStart + scanChunkSize; - size += _scan(bytes, localStart, localEnd); - localStart = localEnd; - } - size += _scan(bytes, localStart, end); - return size; - } - - int _scan(Uint8List bytes, int start, int end) { int size = 0; int flags = 0; for (int i = start; i < end; i++) {