Skip to content

Commit f314527

Browse files
committed
improve the pattern match code generation
1 parent d980b3f commit f314527

31 files changed

+2348
-2370
lines changed

jscomp/test/complex_if_test.js

+14-15
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,21 @@ function escaped(s) {
1616
var n = 0;
1717
for(var i = 0 ,i_finish = s.length; i < i_finish; ++i){
1818
var match = s[i];
19-
var tmp;
20-
if (match >= 32) {
21-
var switcher = match - 34 | 0;
22-
tmp = switcher > 58 || switcher < 0 ? (
23-
switcher >= 93 ? 4 : 1
19+
n = n + (
20+
match >= 32 ? (
21+
match > 92 || match < 34 ? (
22+
match >= 127 ? 4 : 1
23+
) : (
24+
match > 91 || match < 35 ? 2 : 1
25+
)
2426
) : (
25-
switcher > 57 || switcher < 1 ? 2 : 1
26-
);
27-
} else {
28-
tmp = match >= 11 ? (
29-
match !== 13 ? 4 : 2
30-
) : (
31-
match >= 8 ? 2 : 4
32-
);
33-
}
34-
n = n + tmp | 0;
27+
match >= 11 ? (
28+
match !== 13 ? 4 : 2
29+
) : (
30+
match >= 8 ? 2 : 4
31+
)
32+
)
33+
) | 0;
3534
}
3635
if (n === s.length) {
3736
return Bytes.copy(s);

jscomp/test/ext_bytes_test.js

+14-15
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,21 @@ function escaped(s) {
2525
var n = 0;
2626
for(var i = 0 ,i_finish = s.length; i < i_finish; ++i){
2727
var match = s[i];
28-
var tmp;
29-
if (match >= 32) {
30-
var switcher = match - 34 | 0;
31-
tmp = switcher > 58 || switcher < 0 ? (
32-
switcher >= 93 ? 4 : 1
28+
n = n + (
29+
match >= 32 ? (
30+
match > 92 || match < 34 ? (
31+
match >= 127 ? 4 : 1
32+
) : (
33+
match > 91 || match < 35 ? 2 : 1
34+
)
3335
) : (
34-
switcher > 57 || switcher < 1 ? 2 : 1
35-
);
36-
} else {
37-
tmp = match >= 11 ? (
38-
match !== 13 ? 4 : 2
39-
) : (
40-
match >= 8 ? 2 : 4
41-
);
42-
}
43-
n = n + tmp | 0;
36+
match >= 11 ? (
37+
match !== 13 ? 4 : 2
38+
) : (
39+
match >= 8 ? 2 : 4
40+
)
41+
)
42+
) | 0;
4443
}
4544
if (n === s.length) {
4645
return Bytes.copy(s);

jscomp/test/ext_string_test.js

+10-13
Original file line numberDiff line numberDiff line change
@@ -179,15 +179,14 @@ function escaped(s) {
179179
if (match < 32) {
180180
return true;
181181
}
182-
var switcher = match - 34 | 0;
183-
if (switcher > 58 || switcher < 0) {
184-
if (switcher >= 93) {
182+
if (match > 92 || match < 34) {
183+
if (match >= 127) {
185184
return true;
186185
}
187186
_i = i + 1 | 0;
188187
continue ;
189188
}
190-
if (switcher > 57 || switcher < 1) {
189+
if (match > 91 || match < 35) {
191190
return true;
192191
}
193192
_i = i + 1 | 0;
@@ -467,18 +466,16 @@ function is_valid_module_file(s) {
467466
return false;
468467
}
469468
return unsafe_for_all_range(s, 1, len - 1 | 0, (function (x) {
470-
if (x < 65) {
471-
if (x >= 48) {
472-
return x < 58;
469+
if (x >= 65) {
470+
if (x > 96 || x < 91) {
471+
return x < 123;
473472
} else {
474-
return x === 39;
473+
return x === 95;
475474
}
476-
}
477-
var switcher = x - 91 | 0;
478-
if (switcher > 5 || switcher < 0) {
479-
return switcher < 32;
475+
} else if (x >= 48) {
476+
return x < 58;
480477
} else {
481-
return switcher === 4;
478+
return x === 39;
482479
}
483480
}));
484481
}

0 commit comments

Comments
 (0)