Avoid constructing RegExp for every BigInt.tryParse
Change-Id: I323089a17b4fa167ac3d660f5313cc1e6873a994
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/118681
Reviewed-by: Leaf Petersen <leafp@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
diff --git a/sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart b/sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart
index 746ac61..43e0f08 100644
--- a/sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart
+++ b/sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart
@@ -1021,9 +1021,7 @@
static _BigIntImpl _tryParse(String source, {int radix}) {
if (source == "") return null;
- var re = RegExp(r'^\s*([+-]?)((0x[a-f0-9]+)|(\d+)|([a-z0-9]+))\s*$',
- caseSensitive: false);
- var match = re.firstMatch(source);
+ var match = _parseRE.firstMatch(source);
int signIndex = 1;
int hexIndex = 3;
int decimalIndex = 4;
@@ -1065,6 +1063,10 @@
decimalMatch ?? nonDecimalMatch ?? hexMatch, radix, isNegative);
}
+ static RegExp _parseRE = RegExp(
+ r'^\s*([+-]?)((0x[a-f0-9]+)|(\d+)|([a-z0-9]+))\s*$',
+ caseSensitive: false);
+
/// Finds the amount significant digits in the provided [digits] array.
static int _normalize(int used, Uint16List digits) {
while (used > 0 && digits[used - 1] == 0) used--;
diff --git a/sdk/lib/_internal/js_runtime/lib/core_patch.dart b/sdk/lib/_internal/js_runtime/lib/core_patch.dart
index c655fc2..ec8dbc4 100644
--- a/sdk/lib/_internal/js_runtime/lib/core_patch.dart
+++ b/sdk/lib/_internal/js_runtime/lib/core_patch.dart
@@ -1071,9 +1071,7 @@
static _BigIntImpl _tryParse(String source, {int radix}) {
if (source == "") return null;
- var re = new RegExp(r'^\s*([+-]?)((0x[a-f0-9]+)|(\d+)|([a-z0-9]+))\s*$',
- caseSensitive: false);
- var match = re.firstMatch(source);
+ var match = _parseRE.firstMatch(source);
int signIndex = 1;
int hexIndex = 3;
int decimalIndex = 4;
@@ -1115,6 +1113,10 @@
decimalMatch ?? nonDecimalMatch ?? hexMatch, radix, isNegative);
}
+ static RegExp _parseRE = RegExp(
+ r'^\s*([+-]?)((0x[a-f0-9]+)|(\d+)|([a-z0-9]+))\s*$',
+ caseSensitive: false);
+
/// Finds the amount significant digits in the provided [digits] array.
static int _normalize(int used, Uint16List digits) {
while (used > 0 && digits[used - 1] == 0) used--;
diff --git a/sdk/lib/_internal/vm/lib/bigint_patch.dart b/sdk/lib/_internal/vm/lib/bigint_patch.dart
index 5bfda0c..e49305d 100644
--- a/sdk/lib/_internal/vm/lib/bigint_patch.dart
+++ b/sdk/lib/_internal/vm/lib/bigint_patch.dart
@@ -269,9 +269,7 @@
static _BigIntImpl _tryParse(String source, {int radix}) {
if (source == "") return null;
- var re = new RegExp(r'^\s*([+-]?)((0x[a-f0-9]+)|(\d+)|([a-z0-9]+))\s*$',
- caseSensitive: false);
- var match = re.firstMatch(source);
+ var match = _parseRE.firstMatch(source);
int signIndex = 1;
int hexIndex = 3;
int decimalIndex = 4;
@@ -313,6 +311,10 @@
decimalMatch ?? nonDecimalMatch ?? hexMatch, radix, isNegative);
}
+ static RegExp _parseRE = RegExp(
+ r'^\s*([+-]?)((0x[a-f0-9]+)|(\d+)|([a-z0-9]+))\s*$',
+ caseSensitive: false);
+
/// Finds the amount significant digits in the provided [digits] array.
static int _normalize(int used, Uint32List digits) {
while (used > 0 && digits[used - 1] == 0) used--;
diff --git a/sdk_nnbd/lib/_internal/js_dev_runtime/patch/core_patch.dart b/sdk_nnbd/lib/_internal/js_dev_runtime/patch/core_patch.dart
index 7a8ac4b..3665c70 100644
--- a/sdk_nnbd/lib/_internal/js_dev_runtime/patch/core_patch.dart
+++ b/sdk_nnbd/lib/_internal/js_dev_runtime/patch/core_patch.dart
@@ -1023,9 +1023,7 @@
static _BigIntImpl _tryParse(String source, {int radix}) {
if (source == "") return null;
- var re = RegExp(r'^\s*([+-]?)((0x[a-f0-9]+)|(\d+)|([a-z0-9]+))\s*$',
- caseSensitive: false);
- var match = re.firstMatch(source);
+ var match = _parseRE.firstMatch(source);
int signIndex = 1;
int hexIndex = 3;
int decimalIndex = 4;
@@ -1067,6 +1065,10 @@
decimalMatch ?? nonDecimalMatch ?? hexMatch, radix, isNegative);
}
+ static RegExp _parseRE = RegExp(
+ r'^\s*([+-]?)((0x[a-f0-9]+)|(\d+)|([a-z0-9]+))\s*$',
+ caseSensitive: false);
+
/// Finds the amount significant digits in the provided [digits] array.
static int _normalize(int used, Uint16List digits) {
while (used > 0 && digits[used - 1] == 0) used--;
diff --git a/sdk_nnbd/lib/_internal/js_runtime/lib/core_patch.dart b/sdk_nnbd/lib/_internal/js_runtime/lib/core_patch.dart
index 3fb8ccd..64c10cd 100644
--- a/sdk_nnbd/lib/_internal/js_runtime/lib/core_patch.dart
+++ b/sdk_nnbd/lib/_internal/js_runtime/lib/core_patch.dart
@@ -1073,9 +1073,7 @@
static _BigIntImpl _tryParse(String source, {int radix}) {
if (source == "") return null;
- var re = new RegExp(r'^\s*([+-]?)((0x[a-f0-9]+)|(\d+)|([a-z0-9]+))\s*$',
- caseSensitive: false);
- var match = re.firstMatch(source);
+ var match = _parseRE.firstMatch(source);
int signIndex = 1;
int hexIndex = 3;
int decimalIndex = 4;
@@ -1117,6 +1115,10 @@
decimalMatch ?? nonDecimalMatch ?? hexMatch, radix, isNegative);
}
+ static RegExp _parseRE = RegExp(
+ r'^\s*([+-]?)((0x[a-f0-9]+)|(\d+)|([a-z0-9]+))\s*$',
+ caseSensitive: false);
+
/// Finds the amount significant digits in the provided [digits] array.
static int _normalize(int used, Uint16List digits) {
while (used > 0 && digits[used - 1] == 0) used--;
diff --git a/sdk_nnbd/lib/_internal/vm/lib/bigint_patch.dart b/sdk_nnbd/lib/_internal/vm/lib/bigint_patch.dart
index 1730be8..b5d3093 100644
--- a/sdk_nnbd/lib/_internal/vm/lib/bigint_patch.dart
+++ b/sdk_nnbd/lib/_internal/vm/lib/bigint_patch.dart
@@ -271,9 +271,7 @@
static _BigIntImpl _tryParse(String source, {int radix}) {
if (source == "") return null;
- var re = new RegExp(r'^\s*([+-]?)((0x[a-f0-9]+)|(\d+)|([a-z0-9]+))\s*$',
- caseSensitive: false);
- var match = re.firstMatch(source);
+ var match = _parseRE.firstMatch(source);
int signIndex = 1;
int hexIndex = 3;
int decimalIndex = 4;
@@ -315,6 +313,10 @@
decimalMatch ?? nonDecimalMatch ?? hexMatch, radix, isNegative);
}
+ static RegExp _parseRE = RegExp(
+ r'^\s*([+-]?)((0x[a-f0-9]+)|(\d+)|([a-z0-9]+))\s*$',
+ caseSensitive: false);
+
/// Finds the amount significant digits in the provided [digits] array.
static int _normalize(int used, Uint32List digits) {
while (used > 0 && digits[used - 1] == 0) used--;