Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

[M] Change in dart/sdk[main]: Make Dart2JS use the `y` RegExp flag for `matchAsPrefix`.

0 views
Skip to first unread message

Lasse Nielsen (Gerrit)

unread,
Feb 27, 2025, 9:52:52 AMFeb 27
to Stephen Adams, Commit Queue, dart2js-te...@google.com, rev...@dartlang.org
Attention needed from Stephen Adams

Lasse Nielsen added 2 comments

Patchset-level comments
File-level comment, Patchset 3 (Latest):
Lasse Nielsen . resolved

This should make anchored RegExps a little smoother.

It might make `regexpCaptureCount` more expensive since it now creates a RegExp on each invocation. It's a RegExp that matches the empty string quicker than the old one.
May be time to start caching the capture count. WDYT?

File sdk/lib/_internal/js_runtime/lib/regexp_helper.dart
Line 64, Patchset 3 (Latest): get _nativeGlobalVersion {
Lasse Nielsen . resolved

(I expect that we can just drop this RegExp and use the global one instead. But that's for another CL.)

Open in Gerrit

Related details

Attention is currently required from:
  • Stephen Adams
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: I332ebb41cd733346a204345869da16637d775245
Gerrit-Change-Number: 412420
Gerrit-PatchSet: 3
Gerrit-Owner: Lasse Nielsen <l...@google.com>
Gerrit-Reviewer: Lasse Nielsen <l...@google.com>
Gerrit-Reviewer: Stephen Adams <s...@google.com>
Gerrit-Attention: Stephen Adams <s...@google.com>
Gerrit-Comment-Date: Thu, 27 Feb 2025 14:52:47 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
unsatisfied_requirement
open
diffy

Stephen Adams (Gerrit)

unread,
Mar 7, 2025, 5:05:18 PMMar 7
to Lasse Nielsen, Commit Queue, dart2js-te...@google.com, rev...@dartlang.org
Attention needed from Lasse Nielsen

Stephen Adams added 3 comments

Patchset-level comments
Stephen Adams . resolved

There is essentially the same code (with minor differences) in js_dev_runtime/private/

File sdk/lib/_internal/js_runtime/lib/regexp_helper.dart
Line 31, Patchset 3 (Latest): r'new RegExp("(?:)|" + #, #)',
Stephen Adams . unresolved

Having the JavaScript runtime recompile this RegExp might be quite expensive.

Line 44, Patchset 3 (Latest):
Stephen Adams . unresolved

perhaps
```
late final bool hasCaptures = regExpCaptureCount(this);
```

Open in Gerrit

Related details

Attention is currently required from:
  • Lasse Nielsen
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: I332ebb41cd733346a204345869da16637d775245
Gerrit-Change-Number: 412420
Gerrit-PatchSet: 3
Gerrit-Owner: Lasse Nielsen <l...@google.com>
Gerrit-Reviewer: Lasse Nielsen <l...@google.com>
Gerrit-Reviewer: Stephen Adams <s...@google.com>
Gerrit-Attention: Lasse Nielsen <l...@google.com>
Gerrit-Comment-Date: Fri, 07 Mar 2025 22:05:15 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
unsatisfied_requirement
open
diffy

Lasse Nielsen (Gerrit)

unread,
Mar 10, 2025, 7:21:17 AMMar 10
to Stephen Adams, Commit Queue, dart2js-te...@google.com, rev...@dartlang.org
Attention needed from Stephen Adams

Lasse Nielsen added 2 comments

File sdk/lib/_internal/js_runtime/lib/regexp_helper.dart
Line 31, Patchset 3 (Latest): r'new RegExp("(?:)|" + #, #)',
Stephen Adams . unresolved

Having the JavaScript runtime recompile this RegExp might be quite expensive.

Lasse Nielsen

What it did before was to use the `MatchAsPrefix` regexp which would compile the regexp `#|()` instead, which is probably even more expensive with the extra capture. It would only be helped by it *maybe* being compiled before if someone had used `matchAsPrefix` with the same RegExp that they're passing to `split`. Which most likely never happened. People don't reuse RegExps, they create a new one for each purpose.
At least a smart RegExp compiler might see that `(?:)|...` can ignore the `...` part of the pattern.

Caching the result is probably worth doing. It's cheap and paus for itself the moment someone uses `split` with the same RegExp twice, which is more likely than using the RegExp for something else.

The other possible approach that doesn't require compiling a RegExp is to try to parse the regexp pattern, but that's going to be fragile.

Hmm, if we don't need to know the number of capture, just whether it has one, we might be able to just scan the pattern. If seeing `\`, ignore next character, if seeing `[` skip until `]` while still ignoring character after `\`, and if seeing `(` not followed by `?`, or followed by `?<` and then not `=` or `!`, it has a capture. I think that's correct for current JS regexps, and is unlikely to change with future changes. Let me try that.

Or just not using JS `String.prototype.split` with RegExps to begin with. That avoids having to know if it has captures. Just do the looping in Dart.

Stephen Adams . unresolved

perhaps
```
late final bool hasCaptures = regExpCaptureCount(this);
```

Lasse Nielsen

That's fine. (Personally I don't like `late`, but if you know it's efficient here, it's probably fine.)

Open in Gerrit

Related details

Attention is currently required from:
  • Stephen Adams
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: I332ebb41cd733346a204345869da16637d775245
Gerrit-Change-Number: 412420
Gerrit-PatchSet: 3
Gerrit-Owner: Lasse Nielsen <l...@google.com>
Gerrit-Reviewer: Lasse Nielsen <l...@google.com>
Gerrit-Reviewer: Stephen Adams <s...@google.com>
Gerrit-Attention: Stephen Adams <s...@google.com>
Gerrit-Comment-Date: Mon, 10 Mar 2025 11:21:13 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Stephen Adams <s...@google.com>
unsatisfied_requirement
open
diffy

Stephen Adams (Gerrit)

unread,
Mar 13, 2025, 1:23:10 AMMar 13
to Lasse Nielsen, Commit Queue, dart2js-te...@google.com, rev...@dartlang.org
Attention needed from Lasse Nielsen

Stephen Adams added 4 comments

Patchset-level comments
File-level comment, Patchset 5 (Latest):
Stephen Adams . resolved

Would it break anything if RegExp was a factory constructor that could return an existing RegExp?

File sdk/lib/_internal/js_runtime/lib/regexp_helper.dart
Line 38, Patchset 5 (Latest):bool _regExpHasCaptures(String pattern) {
Stephen Adams . unresolved

I'm not sure this carries its weight.

1. Is it correct? It makes me nervous to have multiple places that parse RegExps. I think this needs to be tested.

2. It is more lines of code to maintain and keep in sync with the DDC version.

3. It won't be all that fast until it is JIT-optimized, which might be never.

4. It is might be more bytes of .js download.

Perhaps a hybrid aproach is the sweet spot:

  • cache the result
  • use the `exec` trick...
  • ... but guard it with a simple test like `JS<int>('', '#.indexOf("(")', pattern) < 0`, that catches the majority of split RegExps.

JavaScript RegExps are still evolving.
There are other `(?` groups, luckily non-capturing for now)
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Modifier

Stephen Adams . unresolved

perhaps
```
late final bool hasCaptures = regExpCaptureCount(this);
```

Lasse Nielsen

That's fine. (Personally I don't like `late`, but if you know it's efficient here, it's probably fine.)

Stephen Adams

If you don't like `late`, you can use something like
```
bool? __hasCaptures;
bool get _hasCaptures => __hasCaptures ??= _regExpHasCaptures(pattern);
```

File sdk/lib/_internal/wasm/lib/regexp_helper.dart
Line 22, Patchset 5 (Latest): return s;
Stephen Adams . unresolved

I'd revert this to avoid churning files without changes.

Open in Gerrit

Related details

Attention is currently required from:
  • Lasse Nielsen
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: I332ebb41cd733346a204345869da16637d775245
Gerrit-Change-Number: 412420
Gerrit-PatchSet: 5
Gerrit-Owner: Lasse Nielsen <l...@google.com>
Gerrit-Reviewer: Lasse Nielsen <l...@google.com>
Gerrit-Reviewer: Stephen Adams <s...@google.com>
Gerrit-Attention: Lasse Nielsen <l...@google.com>
Gerrit-Comment-Date: Thu, 13 Mar 2025 05:23:07 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Lasse Nielsen <l...@google.com>
Comment-In-Reply-To: Stephen Adams <s...@google.com>
unsatisfied_requirement
open
diffy

Lasse Nielsen (Gerrit)

unread,
Mar 13, 2025, 8:16:46 AMMar 13
to Stephen Adams, Commit Queue, dart2js-te...@google.com, rev...@dartlang.org
Attention needed from Stephen Adams

Lasse Nielsen added 1 comment

File sdk/lib/_internal/js_runtime/lib/regexp_helper.dart
Line 38, Patchset 5:bool _regExpHasCaptures(String pattern) {
Stephen Adams . unresolved

I'm not sure this carries its weight.

1. Is it correct? It makes me nervous to have multiple places that parse RegExps. I think this needs to be tested.

2. It is more lines of code to maintain and keep in sync with the DDC version.

3. It won't be all that fast until it is JIT-optimized, which might be never.

4. It is might be more bytes of .js download.

Perhaps a hybrid aproach is the sweet spot:

  • cache the result
  • use the `exec` trick...
  • ... but guard it with a simple test like `JS<int>('', '#.indexOf("(")', pattern) < 0`, that catches the majority of split RegExps.

JavaScript RegExps are still evolving.
There are other `(?` groups, luckily non-capturing for now)
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Modifier

Lasse Nielsen
Agree. Let's use the `exec` hack.
(I'd still consider just not using JS `split` with a RegExp, but it's possible that some RegExp with no captures gets used for a alot of splits (most split RegExps won't have captures if they're taken from JS) on long texts, and then it would pay off to use the native version when possible.)
Open in Gerrit

Related details

Attention is currently required from:
  • Stephen Adams
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: I332ebb41cd733346a204345869da16637d775245
Gerrit-Change-Number: 412420
Gerrit-PatchSet: 5
Gerrit-Owner: Lasse Nielsen <l...@google.com>
Gerrit-Reviewer: Lasse Nielsen <l...@google.com>
Gerrit-Reviewer: Stephen Adams <s...@google.com>
Gerrit-Attention: Stephen Adams <s...@google.com>
Gerrit-Comment-Date: Thu, 13 Mar 2025 12:16:39 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Stephen Adams <s...@google.com>
unsatisfied_requirement
open
diffy

Lasse Nielsen (Gerrit)

unread,
Mar 13, 2025, 11:48:13 AMMar 13
to Stephen Adams, Commit Queue, dart2js-te...@google.com, rev...@dartlang.org
Attention needed from Stephen Adams

Lasse Nielsen added 1 comment

Patchset-level comments
Stephen Adams . resolved

Would it break anything if RegExp was a factory constructor that could return an existing RegExp?

Lasse Nielsen

Probably not. I don't think anyone extends RegExp. And if they do, they should stop.
(It's technically breaking to change a generative constructor to factory for a non-final/interface class. The class should have been final. There was probably someone implementing it for mocking somewhere.)

Open in Gerrit

Related details

Attention is currently required from:
  • Stephen Adams
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: I332ebb41cd733346a204345869da16637d775245
Gerrit-Change-Number: 412420
Gerrit-PatchSet: 6
Gerrit-Owner: Lasse Nielsen <l...@google.com>
Gerrit-Reviewer: Lasse Nielsen <l...@google.com>
Gerrit-Reviewer: Stephen Adams <s...@google.com>
Gerrit-Attention: Stephen Adams <s...@google.com>
Gerrit-Comment-Date: Thu, 13 Mar 2025 15:48:09 +0000
unsatisfied_requirement
open
diffy

Stephen Adams (Gerrit)

unread,
Mar 13, 2025, 1:34:51 PMMar 13
to Lasse Nielsen, Commit Queue, dart2js-te...@google.com, rev...@dartlang.org
Attention needed from Lasse Nielsen

Stephen Adams voted and added 1 comment

Votes added by Stephen Adams

Code-Review+1

1 comment

Patchset-level comments
File-level comment, Patchset 6 (Latest):
Stephen Adams . resolved

Thanks for the changes.

There is essentially the same code in lib/_internal/js_dev_runtime/private/regexp_helper.dart

Please keep the DDC version aligned with the dart2js version.

Open in Gerrit

Related details

Attention is currently required from:
  • Lasse Nielsen
Submit Requirements:
  • requirement satisfiedCode-Review
  • requirement satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: I332ebb41cd733346a204345869da16637d775245
Gerrit-Change-Number: 412420
Gerrit-PatchSet: 6
Gerrit-Owner: Lasse Nielsen <l...@google.com>
Gerrit-Reviewer: Lasse Nielsen <l...@google.com>
Gerrit-Reviewer: Stephen Adams <s...@google.com>
Gerrit-Attention: Lasse Nielsen <l...@google.com>
Gerrit-Comment-Date: Thu, 13 Mar 2025 17:34:48 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
satisfied_requirement
open
diffy

Stephen Adams (Gerrit)

unread,
Mar 13, 2025, 1:42:18 PMMar 13
to Lasse Nielsen, Commit Queue, dart2js-te...@google.com, rev...@dartlang.org
Attention needed from Lasse Nielsen

Stephen Adams added 1 comment

Commit Message
Line 14, Patchset 6 (Latest):The hacked RegExp was also used by `regexpCaptureCount`,
Stephen Adams . unresolved

The text could be cleaned up or deleted.

Open in Gerrit

Related details

Attention is currently required from:
  • Lasse Nielsen
Submit Requirements:
  • requirement satisfiedCode-Review
  • requirement satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: I332ebb41cd733346a204345869da16637d775245
Gerrit-Change-Number: 412420
Gerrit-PatchSet: 6
Gerrit-Owner: Lasse Nielsen <l...@google.com>
Gerrit-Reviewer: Lasse Nielsen <l...@google.com>
Gerrit-Reviewer: Stephen Adams <s...@google.com>
Gerrit-Attention: Lasse Nielsen <l...@google.com>
Gerrit-Comment-Date: Thu, 13 Mar 2025 17:42:16 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
satisfied_requirement
open
diffy

Lasse Nielsen (Gerrit)

unread,
Mar 14, 2025, 7:20:18 AMMar 14
to Stephen Adams, Commit Queue, dart2js-te...@google.com, rev...@dartlang.org

Lasse Nielsen voted Commit-Queue+2

Commit-Queue+2
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement satisfiedCode-Review
  • requirement satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: I332ebb41cd733346a204345869da16637d775245
Gerrit-Change-Number: 412420
Gerrit-PatchSet: 7
Gerrit-Owner: Lasse Nielsen <l...@google.com>
Gerrit-Reviewer: Lasse Nielsen <l...@google.com>
Gerrit-Reviewer: Stephen Adams <s...@google.com>
Gerrit-Comment-Date: Fri, 14 Mar 2025 11:20:13 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
satisfied_requirement
open
diffy

Lasse Nielsen (Gerrit)

unread,
Mar 14, 2025, 7:23:09 AMMar 14
to Stephen Adams, Commit Queue, dart2js-te...@google.com, rev...@dartlang.org
Attention needed from Stephen Adams

Lasse Nielsen added 3 comments

Patchset-level comments
Stephen Adams . resolved

Thanks for the changes.

There is essentially the same code in lib/_internal/js_dev_runtime/private/regexp_helper.dart

Please keep the DDC version aligned with the dart2js version.

Lasse Nielsen

That is the plan. Doing this one first, to get it right and reviewed, so the others (DDC *and* Wasm) should be slam-dunks.

File-level comment, Patchset 8 (Latest):
Lasse Nielsen . resolved

Fixed the typo in the wasm file. Lost the +1. 😞

Commit Message
Line 14, Patchset 6:The hacked RegExp was also used by `regexpCaptureCount`,
Stephen Adams . resolved

The text could be cleaned up or deleted.

Lasse Nielsen

Will do.

Open in Gerrit

Related details

Attention is currently required from:
  • Stephen Adams
Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: sdk
    Gerrit-Branch: main
    Gerrit-Change-Id: I332ebb41cd733346a204345869da16637d775245
    Gerrit-Change-Number: 412420
    Gerrit-PatchSet: 8
    Gerrit-Owner: Lasse Nielsen <l...@google.com>
    Gerrit-Reviewer: Lasse Nielsen <l...@google.com>
    Gerrit-Reviewer: Stephen Adams <s...@google.com>
    Gerrit-Attention: Stephen Adams <s...@google.com>
    Gerrit-Comment-Date: Fri, 14 Mar 2025 11:23:04 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Comment-In-Reply-To: Stephen Adams <s...@google.com>
    unsatisfied_requirement
    open
    diffy

    Lasse Nielsen (Gerrit)

    unread,
    Mar 14, 2025, 7:23:25 AMMar 14
    to Stephen Adams, Commit Queue, dart2js-te...@google.com, rev...@dartlang.org
    Attention needed from Stephen Adams

    Lasse Nielsen voted

    Auto-Submit+1
    Commit-Queue+1
    Open in Gerrit

    Related details

    Attention is currently required from:
    • Stephen Adams
    Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: sdk
    Gerrit-Branch: main
    Gerrit-Change-Id: I332ebb41cd733346a204345869da16637d775245
    Gerrit-Change-Number: 412420
    Gerrit-PatchSet: 8
    Gerrit-Owner: Lasse Nielsen <l...@google.com>
    Gerrit-Reviewer: Lasse Nielsen <l...@google.com>
    Gerrit-Reviewer: Stephen Adams <s...@google.com>
    Gerrit-Attention: Stephen Adams <s...@google.com>
    Gerrit-Comment-Date: Fri, 14 Mar 2025 11:23:20 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: Yes
    unsatisfied_requirement
    open
    diffy

    Lasse Nielsen (Gerrit)

    unread,
    Mar 14, 2025, 7:24:01 AMMar 14
    to Stephen Adams, Commit Queue, dart2js-te...@google.com, rev...@dartlang.org
    Attention needed from Stephen Adams

    Lasse Nielsen added 4 comments

    File sdk/lib/_internal/js_runtime/lib/regexp_helper.dart
    Line 31, Patchset 3: r'new RegExp("(?:)|" + #, #)',
    Stephen Adams . resolved

    Having the JavaScript runtime recompile this RegExp might be quite expensive.

    Lasse Nielsen

    What it did before was to use the `MatchAsPrefix` regexp which would compile the regexp `#|()` instead, which is probably even more expensive with the extra capture. It would only be helped by it *maybe* being compiled before if someone had used `matchAsPrefix` with the same RegExp that they're passing to `split`. Which most likely never happened. People don't reuse RegExps, they create a new one for each purpose.
    At least a smart RegExp compiler might see that `(?:)|...` can ignore the `...` part of the pattern.

    Caching the result is probably worth doing. It's cheap and paus for itself the moment someone uses `split` with the same RegExp twice, which is more likely than using the RegExp for something else.

    The other possible approach that doesn't require compiling a RegExp is to try to parse the regexp pattern, but that's going to be fragile.

    Hmm, if we don't need to know the number of capture, just whether it has one, we might be able to just scan the pattern. If seeing `\`, ignore next character, if seeing `[` skip until `]` while still ignoring character after `\`, and if seeing `(` not followed by `?`, or followed by `?<` and then not `=` or `!`, it has a capture. I think that's correct for current JS regexps, and is unlikely to change with future changes. Let me try that.

    Or just not using JS `String.prototype.split` with RegExps to begin with. That avoids having to know if it has captures. Just do the looping in Dart.

    Lasse Nielsen

    Done

    Line 38, Patchset 5:bool _regExpHasCaptures(String pattern) {
    Stephen Adams . resolved

    I'm not sure this carries its weight.

    1. Is it correct? It makes me nervous to have multiple places that parse RegExps. I think this needs to be tested.

    2. It is more lines of code to maintain and keep in sync with the DDC version.

    3. It won't be all that fast until it is JIT-optimized, which might be never.

    4. It is might be more bytes of .js download.

    Perhaps a hybrid aproach is the sweet spot:

    • cache the result
    • use the `exec` trick...
    • ... but guard it with a simple test like `JS<int>('', '#.indexOf("(")', pattern) < 0`, that catches the majority of split RegExps.

    JavaScript RegExps are still evolving.
    There are other `(?` groups, luckily non-capturing for now)
    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Modifier

    Lasse Nielsen
    Agree. Let's use the `exec` hack.
    (I'd still consider just not using JS `split` with a RegExp, but it's possible that some RegExp with no captures gets used for a alot of splits (most split RegExps won't have captures if they're taken from JS) on long texts, and then it would pay off to use the native version when possible.)
    Lasse Nielsen

    Done

    Line 44, Patchset 3:
    Stephen Adams . resolved

    perhaps
    ```
    late final bool hasCaptures = regExpCaptureCount(this);
    ```

    Lasse Nielsen

    That's fine. (Personally I don't like `late`, but if you know it's efficient here, it's probably fine.)

    Stephen Adams

    If you don't like `late`, you can use something like
    ```
    bool? __hasCaptures;
    bool get _hasCaptures => __hasCaptures ??= _regExpHasCaptures(pattern);
    ```

    Lasse Nielsen

    Done

    File sdk/lib/_internal/wasm/lib/regexp_helper.dart
    Line 22, Patchset 5: return s;
    Stephen Adams . unresolved

    I'd revert this to avoid churning files without changes.

    Lasse Nielsen

    Done, but lost the +1 in the process.

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Stephen Adams
    Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: sdk
    Gerrit-Branch: main
    Gerrit-Change-Id: I332ebb41cd733346a204345869da16637d775245
    Gerrit-Change-Number: 412420
    Gerrit-PatchSet: 8
    Gerrit-Owner: Lasse Nielsen <l...@google.com>
    Gerrit-Reviewer: Lasse Nielsen <l...@google.com>
    Gerrit-Reviewer: Stephen Adams <s...@google.com>
    Gerrit-Attention: Stephen Adams <s...@google.com>
    Gerrit-Comment-Date: Fri, 14 Mar 2025 11:23:56 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    unsatisfied_requirement
    open
    diffy

    Stephen Adams (Gerrit)

    unread,
    Mar 14, 2025, 2:34:18 PMMar 14
    to Lasse Nielsen, Commit Queue, dart2js-te...@google.com, rev...@dartlang.org
    Attention needed from Lasse Nielsen

    Stephen Adams voted Code-Review+1

    Code-Review+1
    Open in Gerrit

    Related details

    Attention is currently required from:
    • Lasse Nielsen
    Submit Requirements:
    • requirement satisfiedCode-Review
    • requirement satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: sdk
    Gerrit-Branch: main
    Gerrit-Change-Id: I332ebb41cd733346a204345869da16637d775245
    Gerrit-Change-Number: 412420
    Gerrit-PatchSet: 8
    Gerrit-Owner: Lasse Nielsen <l...@google.com>
    Gerrit-Reviewer: Lasse Nielsen <l...@google.com>
    Gerrit-Reviewer: Stephen Adams <s...@google.com>
    Gerrit-Attention: Lasse Nielsen <l...@google.com>
    Gerrit-Comment-Date: Fri, 14 Mar 2025 18:34:11 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: Yes
    satisfied_requirement
    open
    diffy

    Lasse Nielsen (Gerrit)

    unread,
    Mar 17, 2025, 4:35:03 AMMar 17
    to Stephen Adams, Commit Queue, dart2js-te...@google.com, rev...@dartlang.org

    Lasse Nielsen voted Commit-Queue+2

    Commit-Queue+2
    Open in Gerrit

    Related details

    Attention set is empty
    Submit Requirements:
    • requirement satisfiedCode-Review
    • requirement satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: sdk
    Gerrit-Branch: main
    Gerrit-Change-Id: I332ebb41cd733346a204345869da16637d775245
    Gerrit-Change-Number: 412420
    Gerrit-PatchSet: 8
    Gerrit-Owner: Lasse Nielsen <l...@google.com>
    Gerrit-Reviewer: Lasse Nielsen <l...@google.com>
    Gerrit-Reviewer: Stephen Adams <s...@google.com>
    Gerrit-Comment-Date: Mon, 17 Mar 2025 08:34:59 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: Yes
    satisfied_requirement
    open
    diffy

    Commit Queue (Gerrit)

    unread,
    Mar 17, 2025, 5:11:07 AMMar 17
    to Lasse Nielsen, Stephen Adams, dart2js-te...@google.com, rev...@dartlang.org

    Commit Queue submitted the change

    Change information

    Commit message:
    Make Dart2JS use the `y` RegExp flag for `matchAsPrefix`.

    The implementation for `matchAsPrefix` predates the sticky `y` flag
    for JS regexps, so it had a hack that modified the RegExp pattern to ensure that it only matched at a particular position.
    This hack is no longer necessary, so the anchored RegExp can use the
    same RegExp source as the plain and global RegExp, which may let the JS engine better reuse RegExp compilation.
    Change-Id: I332ebb41cd733346a204345869da16637d775245
    Auto-Submit: Lasse Nielsen <l...@google.com>
    Commit-Queue: Lasse Nielsen <l...@google.com>
    Reviewed-by: Stephen Adams <s...@google.com>
    Files:
    • M sdk/lib/_internal/js_runtime/lib/interceptors.dart
    • M sdk/lib/_internal/js_runtime/lib/js_string.dart
    • M sdk/lib/_internal/js_runtime/lib/regexp_helper.dart
    Change size: M
    Delta: 3 files changed, 145 insertions(+), 74 deletions(-)
    Branch: refs/heads/main
    Submit Requirements:
    • requirement satisfiedCode-Review: +1 by Stephen Adams
    Open in Gerrit
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: merged
    Gerrit-Project: sdk
    Gerrit-Branch: main
    Gerrit-Change-Id: I332ebb41cd733346a204345869da16637d775245
    Gerrit-Change-Number: 412420
    Gerrit-PatchSet: 9
    Gerrit-Owner: Lasse Nielsen <l...@google.com>
    open
    diffy
    satisfied_requirement
    Reply all
    Reply to author
    Forward
    0 new messages