mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 10:33:28 +00:00
[dart2wasm] Use unchecked codeUnitAt in int.parse
Change-Id: I60c2a9a56ce9693061054fd72005e52fc6889aab Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/372901 Reviewed-by: Martin Kustermann <kustermann@google.com> Commit-Queue: Ömer Ağacan <omersa@google.com>
This commit is contained in:
parent
43452cdd6c
commit
9fbe418aa3
|
@ -3,6 +3,7 @@
|
||||||
// BSD-style license that can be found in the LICENSE file.
|
// BSD-style license that can be found in the LICENSE file.
|
||||||
|
|
||||||
import "dart:_internal" show has63BitSmis, patch, unsafeCast;
|
import "dart:_internal" show has63BitSmis, patch, unsafeCast;
|
||||||
|
import "dart:_string" show StringUncheckedOperations;
|
||||||
import "dart:typed_data" show Int64List;
|
import "dart:typed_data" show Int64List;
|
||||||
|
|
||||||
@patch
|
@patch
|
||||||
|
@ -11,7 +12,7 @@ class int {
|
||||||
assert(first <= last);
|
assert(first <= last);
|
||||||
var ix = first;
|
var ix = first;
|
||||||
var sign = 1;
|
var sign = 1;
|
||||||
var c = str.codeUnitAt(ix);
|
var c = str.codeUnitAtUnchecked(ix);
|
||||||
// Check for leading '+' or '-'.
|
// Check for leading '+' or '-'.
|
||||||
if ((c == 0x2b) || (c == 0x2d)) {
|
if ((c == 0x2b) || (c == 0x2d)) {
|
||||||
ix++;
|
ix++;
|
||||||
|
@ -26,7 +27,7 @@ class int {
|
||||||
}
|
}
|
||||||
var result = 0;
|
var result = 0;
|
||||||
for (int i = ix; i <= last; i++) {
|
for (int i = ix; i <= last; i++) {
|
||||||
var c = 0x30 ^ str.codeUnitAt(i);
|
var c = 0x30 ^ str.codeUnitAtUnchecked(i);
|
||||||
if (9 < c) {
|
if (9 < c) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -60,7 +61,7 @@ class int {
|
||||||
}
|
}
|
||||||
int start = source.firstNonWhitespace();
|
int start = source.firstNonWhitespace();
|
||||||
|
|
||||||
int first = source.codeUnitAt(start);
|
int first = source.codeUnitAtUnchecked(start);
|
||||||
int sign = 1;
|
int sign = 1;
|
||||||
if (first == 0x2b /* + */ || first == 0x2d /* - */) {
|
if (first == 0x2b /* + */ || first == 0x2d /* - */) {
|
||||||
sign = 0x2c - first; // -1 if '-', +1 if '+'.
|
sign = 0x2c - first; // -1 if '-', +1 if '+'.
|
||||||
|
@ -68,7 +69,7 @@ class int {
|
||||||
if (start == end) {
|
if (start == end) {
|
||||||
return _handleFormatError(onError, source, end, radix, null);
|
return _handleFormatError(onError, source, end, radix, null);
|
||||||
}
|
}
|
||||||
first = source.codeUnitAt(start);
|
first = source.codeUnitAtUnchecked(start);
|
||||||
}
|
}
|
||||||
if (radix == null) {
|
if (radix == null) {
|
||||||
// check for 0x prefix.
|
// check for 0x prefix.
|
||||||
|
@ -76,7 +77,7 @@ class int {
|
||||||
if (first == 0x30 /* 0 */) {
|
if (first == 0x30 /* 0 */) {
|
||||||
index++;
|
index++;
|
||||||
if (index == end) return 0;
|
if (index == end) return 0;
|
||||||
first = source.codeUnitAt(index);
|
first = source.codeUnitAtUnchecked(index);
|
||||||
if ((first | 0x20) == 0x78 /* x */) {
|
if ((first | 0x20) == 0x78 /* x */) {
|
||||||
index++;
|
index++;
|
||||||
if (index == end) {
|
if (index == end) {
|
||||||
|
@ -196,13 +197,13 @@ class int {
|
||||||
_Smi result = unsafeCast<_Smi>(0);
|
_Smi result = unsafeCast<_Smi>(0);
|
||||||
if (radix <= 10) {
|
if (radix <= 10) {
|
||||||
for (int i = start; i < end; i++) {
|
for (int i = start; i < end; i++) {
|
||||||
int digit = source.codeUnitAt(i) ^ 0x30;
|
int digit = source.codeUnitAtUnchecked(i) ^ 0x30;
|
||||||
if (digit >= radix) return null;
|
if (digit >= radix) return null;
|
||||||
result = (radix * result + digit) as _Smi;
|
result = (radix * result + digit) as _Smi;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (int i = start; i < end; i++) {
|
for (int i = start; i < end; i++) {
|
||||||
int char = source.codeUnitAt(i);
|
int char = source.codeUnitAtUnchecked(i);
|
||||||
int digit = char ^ 0x30;
|
int digit = char ^ 0x30;
|
||||||
if (digit > 9) {
|
if (digit > 9) {
|
||||||
digit = (char | 0x20) - (0x61 - 10);
|
digit = (char | 0x20) - (0x61 - 10);
|
||||||
|
|
Loading…
Reference in a new issue