Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 892fcf2

Browse files
rakudramacommit-bot@chromium.org
authored andcommitted
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>
1 parent b4751d5 commit 892fcf2

File tree

6 files changed

+30
-18
lines changed

6 files changed

+30
-18
lines changed

sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,9 +1021,7 @@ class _BigIntImpl implements BigInt {
10211021
static _BigIntImpl _tryParse(String source, {int radix}) {
10221022
if (source == "") return null;
10231023

1024-
var re = RegExp(r'^\s*([+-]?)((0x[a-f0-9]+)|(\d+)|([a-z0-9]+))\s*$',
1025-
caseSensitive: false);
1026-
var match = re.firstMatch(source);
1024+
var match = _parseRE.firstMatch(source);
10271025
int signIndex = 1;
10281026
int hexIndex = 3;
10291027
int decimalIndex = 4;
@@ -1065,6 +1063,10 @@ class _BigIntImpl implements BigInt {
10651063
decimalMatch ?? nonDecimalMatch ?? hexMatch, radix, isNegative);
10661064
}
10671065

1066+
static RegExp _parseRE = RegExp(
1067+
r'^\s*([+-]?)((0x[a-f0-9]+)|(\d+)|([a-z0-9]+))\s*$',
1068+
caseSensitive: false);
1069+
10681070
/// Finds the amount significant digits in the provided [digits] array.
10691071
static int _normalize(int used, Uint16List digits) {
10701072
while (used > 0 && digits[used - 1] == 0) used--;

sdk/lib/_internal/js_runtime/lib/core_patch.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,9 +1071,7 @@ class _BigIntImpl implements BigInt {
10711071
static _BigIntImpl _tryParse(String source, {int radix}) {
10721072
if (source == "") return null;
10731073

1074-
var re = new RegExp(r'^\s*([+-]?)((0x[a-f0-9]+)|(\d+)|([a-z0-9]+))\s*$',
1075-
caseSensitive: false);
1076-
var match = re.firstMatch(source);
1074+
var match = _parseRE.firstMatch(source);
10771075
int signIndex = 1;
10781076
int hexIndex = 3;
10791077
int decimalIndex = 4;
@@ -1115,6 +1113,10 @@ class _BigIntImpl implements BigInt {
11151113
decimalMatch ?? nonDecimalMatch ?? hexMatch, radix, isNegative);
11161114
}
11171115

1116+
static RegExp _parseRE = RegExp(
1117+
r'^\s*([+-]?)((0x[a-f0-9]+)|(\d+)|([a-z0-9]+))\s*$',
1118+
caseSensitive: false);
1119+
11181120
/// Finds the amount significant digits in the provided [digits] array.
11191121
static int _normalize(int used, Uint16List digits) {
11201122
while (used > 0 && digits[used - 1] == 0) used--;

sdk/lib/_internal/vm/lib/bigint_patch.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,7 @@ class _BigIntImpl implements BigInt {
269269
static _BigIntImpl _tryParse(String source, {int radix}) {
270270
if (source == "") return null;
271271

272-
var re = new RegExp(r'^\s*([+-]?)((0x[a-f0-9]+)|(\d+)|([a-z0-9]+))\s*$',
273-
caseSensitive: false);
274-
var match = re.firstMatch(source);
272+
var match = _parseRE.firstMatch(source);
275273
int signIndex = 1;
276274
int hexIndex = 3;
277275
int decimalIndex = 4;
@@ -313,6 +311,10 @@ class _BigIntImpl implements BigInt {
313311
decimalMatch ?? nonDecimalMatch ?? hexMatch, radix, isNegative);
314312
}
315313

314+
static RegExp _parseRE = RegExp(
315+
r'^\s*([+-]?)((0x[a-f0-9]+)|(\d+)|([a-z0-9]+))\s*$',
316+
caseSensitive: false);
317+
316318
/// Finds the amount significant digits in the provided [digits] array.
317319
static int _normalize(int used, Uint32List digits) {
318320
while (used > 0 && digits[used - 1] == 0) used--;

sdk_nnbd/lib/_internal/js_dev_runtime/patch/core_patch.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,9 +1023,7 @@ class _BigIntImpl implements BigInt {
10231023
static _BigIntImpl _tryParse(String source, {int radix}) {
10241024
if (source == "") return null;
10251025

1026-
var re = RegExp(r'^\s*([+-]?)((0x[a-f0-9]+)|(\d+)|([a-z0-9]+))\s*$',
1027-
caseSensitive: false);
1028-
var match = re.firstMatch(source);
1026+
var match = _parseRE.firstMatch(source);
10291027
int signIndex = 1;
10301028
int hexIndex = 3;
10311029
int decimalIndex = 4;
@@ -1067,6 +1065,10 @@ class _BigIntImpl implements BigInt {
10671065
decimalMatch ?? nonDecimalMatch ?? hexMatch, radix, isNegative);
10681066
}
10691067

1068+
static RegExp _parseRE = RegExp(
1069+
r'^\s*([+-]?)((0x[a-f0-9]+)|(\d+)|([a-z0-9]+))\s*$',
1070+
caseSensitive: false);
1071+
10701072
/// Finds the amount significant digits in the provided [digits] array.
10711073
static int _normalize(int used, Uint16List digits) {
10721074
while (used > 0 && digits[used - 1] == 0) used--;

sdk_nnbd/lib/_internal/js_runtime/lib/core_patch.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,9 +1073,7 @@ class _BigIntImpl implements BigInt {
10731073
static _BigIntImpl _tryParse(String source, {int radix}) {
10741074
if (source == "") return null;
10751075

1076-
var re = new RegExp(r'^\s*([+-]?)((0x[a-f0-9]+)|(\d+)|([a-z0-9]+))\s*$',
1077-
caseSensitive: false);
1078-
var match = re.firstMatch(source);
1076+
var match = _parseRE.firstMatch(source);
10791077
int signIndex = 1;
10801078
int hexIndex = 3;
10811079
int decimalIndex = 4;
@@ -1117,6 +1115,10 @@ class _BigIntImpl implements BigInt {
11171115
decimalMatch ?? nonDecimalMatch ?? hexMatch, radix, isNegative);
11181116
}
11191117

1118+
static RegExp _parseRE = RegExp(
1119+
r'^\s*([+-]?)((0x[a-f0-9]+)|(\d+)|([a-z0-9]+))\s*$',
1120+
caseSensitive: false);
1121+
11201122
/// Finds the amount significant digits in the provided [digits] array.
11211123
static int _normalize(int used, Uint16List digits) {
11221124
while (used > 0 && digits[used - 1] == 0) used--;

sdk_nnbd/lib/_internal/vm/lib/bigint_patch.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,7 @@ class _BigIntImpl implements BigInt {
271271
static _BigIntImpl _tryParse(String source, {int radix}) {
272272
if (source == "") return null;
273273

274-
var re = new RegExp(r'^\s*([+-]?)((0x[a-f0-9]+)|(\d+)|([a-z0-9]+))\s*$',
275-
caseSensitive: false);
276-
var match = re.firstMatch(source);
274+
var match = _parseRE.firstMatch(source);
277275
int signIndex = 1;
278276
int hexIndex = 3;
279277
int decimalIndex = 4;
@@ -315,6 +313,10 @@ class _BigIntImpl implements BigInt {
315313
decimalMatch ?? nonDecimalMatch ?? hexMatch, radix, isNegative);
316314
}
317315

316+
static RegExp _parseRE = RegExp(
317+
r'^\s*([+-]?)((0x[a-f0-9]+)|(\d+)|([a-z0-9]+))\s*$',
318+
caseSensitive: false);
319+
318320
/// Finds the amount significant digits in the provided [digits] array.
319321
static int _normalize(int used, Uint32List digits) {
320322
while (used > 0 && digits[used - 1] == 0) used--;

0 commit comments

Comments
 (0)