Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(994)

Issue 15709018: Proof-of-concept matchPrefix on Pattern. (Closed)

Created:
7 years, 6 months ago by Lasse Reichstein Nielsen
Modified:
7 years, 6 months ago
Reviewers:
floitsch, sra1
CC:
reviews_dartlang.org, regis, ngeoffray
Visibility:
Public.

Description

Proof-of-concept matchPrefix on Pattern. Can be used to implement startsWith (and endsWith with a loop). R=floitsch@google.com Committed: https://code.google.com/p/dart/source/detail?r=23897

Patch Set 1 #

Total comments: 8

Patch Set 2 : Changed name to matchAsPrefix. Added docs and tests. #

Patch Set 3 : Addressed other comments. #

Unified diffs Side-by-side diffs Delta from patch set Stats (+146 lines, -1 line) Patch
M runtime/lib/regexp_patch.dart View 1 1 chunk +12 lines, -0 lines 0 comments Download
M runtime/lib/string_patch.dart View 1 1 chunk +13 lines, -0 lines 0 comments Download
M sdk/lib/_internal/compiler/implementation/lib/interceptors.dart View 1 1 chunk +2 lines, -1 line 0 comments Download
M sdk/lib/_internal/compiler/implementation/lib/js_string.dart View 1 2 1 chunk +14 lines, -0 lines 0 comments Download
M sdk/lib/_internal/compiler/implementation/lib/regexp_helper.dart View 1 2 2 chunks +26 lines, -0 lines 0 comments Download
M sdk/lib/core/pattern.dart View 1 1 chunk +23 lines, -0 lines 0 comments Download
M tests/corelib/string_pattern_test.dart View 1 2 chunks +20 lines, -0 lines 0 comments Download
M tests/language/reg_exp_test.dart View 1 1 chunk +36 lines, -0 lines 0 comments Download

Messages

Total messages: 5 (0 generated)
Lasse Reichstein Nielsen
I think this would be acceptable.
7 years, 6 months ago (2013-06-11 11:11:21 UTC) #1
floitsch
LGTM with tests. https://codereview.chromium.org/15709018/diff/1/sdk/lib/_internal/compiler/implementation/lib/js_string.dart File sdk/lib/_internal/compiler/implementation/lib/js_string.dart (right): https://codereview.chromium.org/15709018/diff/1/sdk/lib/_internal/compiler/implementation/lib/js_string.dart#newcode33 sdk/lib/_internal/compiler/implementation/lib/js_string.dart:33: for (int i = 0; i ...
7 years, 6 months ago (2013-06-11 12:45:24 UTC) #2
Lasse Reichstein Nielsen
Committed patchset #3 manually as r23897 (presubmit successful).
7 years, 6 months ago (2013-06-12 08:37:49 UTC) #3
Lasse Reichstein Nielsen
https://codereview.chromium.org/15709018/diff/1/sdk/lib/_internal/compiler/implementation/lib/js_string.dart File sdk/lib/_internal/compiler/implementation/lib/js_string.dart (right): https://codereview.chromium.org/15709018/diff/1/sdk/lib/_internal/compiler/implementation/lib/js_string.dart#newcode33 sdk/lib/_internal/compiler/implementation/lib/js_string.dart:33: for (int i = 0; i < this.length; i++) ...
7 years, 6 months ago (2013-06-12 09:24:05 UTC) #4
sra1
7 years, 6 months ago (2013-06-13 17:30:53 UTC) #5
Message was sent while issue was closed.
https://codereview.chromium.org/15709018/diff/1/sdk/lib/_internal/compiler/im...
File sdk/lib/_internal/compiler/implementation/lib/js_string.dart (right):

https://codereview.chromium.org/15709018/diff/1/sdk/lib/_internal/compiler/im...
sdk/lib/_internal/compiler/implementation/lib/js_string.dart:33: for (int i = 0;
i < this.length; i++) {
On 2013/06/12 09:24:05, Lasse Reichstein Nielsen wrote:
> I'm not sure it can be made that much faster. If it's translated to similar JS
> code, I think an optimizing VM like V8 should do fine on it.

The code is pretty horrible.
dart2js inlines codeUnitAt which contains bounds checks.



  matchAsPrefix$2: function(receiver, string, start) {
    var t1, t2, i, t3;
    if (start < 0 || start > string.length)
      throw $.wrapException(new $.RangeError("value " + $.S(start) + " not in
range 0.." + string.length));
    t1 = receiver.length;
    t2 = string.length;
    if (start + t1 > t2)
      return;
    for (i = 0; i < t1; ++i) {
      t3 = start + i;
      if (t3 < 0)
        $.throwExpression(new $.RangeError("value " + $.S(t3)));
      if (t3 >= t2)
        $.throwExpression(new $.RangeError("value " + $.S(t3)));
      t3 = string.charCodeAt(t3);
      if (i >= t1)
        $.throwExpression(new $.RangeError("value " + i));
      if (t3 !== receiver.charCodeAt(i))
        return;
    }
    return new $.StringMatch(start, string, receiver);
  },

Options:
1. Improve the (hand written) bounds checking elimination
2. Tweak the code by replacing  x.codeUnitAt(i) by JS('int', '#.charCodeAt(#)',
x, i)
3. Change the code to use JavaScript string level operations

I think #2 is fair game.

Powered by Google App Engine
This is Rietveld 408576698