Chromium Code Reviews| Index: sdk/lib/_internal/compiler/implementation/tree/nodes.dart |
| diff --git a/sdk/lib/_internal/compiler/implementation/tree/nodes.dart b/sdk/lib/_internal/compiler/implementation/tree/nodes.dart |
| index bd96b3c213f3c1645620a7fd7953ddbff3774b02..ca5d81e90a0b873b7d8dbf89e67ebe862b700d00 100644 |
| --- a/sdk/lib/_internal/compiler/implementation/tree/nodes.dart |
| +++ b/sdk/lib/_internal/compiler/implementation/tree/nodes.dart |
| @@ -826,58 +826,38 @@ class LiteralBool extends Literal<bool> { |
| class StringQuoting { |
| - static const StringQuoting SINGLELINE_DQ = |
| - const StringQuoting($DQ, raw: false, leftQuoteLength: 1); |
| - static const StringQuoting RAW_SINGLELINE_DQ = |
| - const StringQuoting($DQ, raw: true, leftQuoteLength: 1); |
| - static const StringQuoting MULTILINE_DQ = |
| - const StringQuoting($DQ, raw: false, leftQuoteLength: 3); |
| - static const StringQuoting RAW_MULTILINE_DQ = |
| - const StringQuoting($DQ, raw: true, leftQuoteLength: 3); |
| - static const StringQuoting MULTILINE_NL_DQ = |
| - const StringQuoting($DQ, raw: false, leftQuoteLength: 4); |
| - static const StringQuoting RAW_MULTILINE_NL_DQ = |
| - const StringQuoting($DQ, raw: true, leftQuoteLength: 4); |
| - static const StringQuoting MULTILINE_NL2_DQ = |
| - const StringQuoting($DQ, raw: false, leftQuoteLength: 5); |
| - static const StringQuoting RAW_MULTILINE_NL2_DQ = |
| - const StringQuoting($DQ, raw: true, leftQuoteLength: 5); |
| - static const StringQuoting SINGLELINE_SQ = |
| - const StringQuoting($SQ, raw: false, leftQuoteLength: 1); |
| - static const StringQuoting RAW_SINGLELINE_SQ = |
| - const StringQuoting($SQ, raw: true, leftQuoteLength: 1); |
| - static const StringQuoting MULTILINE_SQ = |
| - const StringQuoting($SQ, raw: false, leftQuoteLength: 3); |
| - static const StringQuoting RAW_MULTILINE_SQ = |
| - const StringQuoting($SQ, raw: true, leftQuoteLength: 3); |
| - static const StringQuoting MULTILINE_NL_SQ = |
| - const StringQuoting($SQ, raw: false, leftQuoteLength: 4); |
| - static const StringQuoting RAW_MULTILINE_NL_SQ = |
| - const StringQuoting($SQ, raw: true, leftQuoteLength: 4); |
| - static const StringQuoting MULTILINE_NL2_SQ = |
| - const StringQuoting($SQ, raw: false, leftQuoteLength: 5); |
| - static const StringQuoting RAW_MULTILINE_NL2_SQ = |
| - const StringQuoting($SQ, raw: true, leftQuoteLength: 5); |
| - |
| - |
| - static const List<StringQuoting> mapping = const <StringQuoting>[ |
| - SINGLELINE_DQ, |
| - RAW_SINGLELINE_DQ, |
| - MULTILINE_DQ, |
| - RAW_MULTILINE_DQ, |
| - MULTILINE_NL_DQ, |
| - RAW_MULTILINE_NL_DQ, |
| - MULTILINE_NL2_DQ, |
| - RAW_MULTILINE_NL2_DQ, |
| - SINGLELINE_SQ, |
| - RAW_SINGLELINE_SQ, |
| - MULTILINE_SQ, |
| - RAW_MULTILINE_SQ, |
| - MULTILINE_NL_SQ, |
| - RAW_MULTILINE_NL_SQ, |
| - MULTILINE_NL2_SQ, |
| - RAW_MULTILINE_NL2_SQ |
| + |
| + /// Cache of common quotings. |
| + static const List<StringQuoting> _mapping = const <StringQuoting>[ |
| + const StringQuoting($SQ, raw: false, leftQuoteLength: 1), |
| + const StringQuoting($SQ, raw: true, leftQuoteLength: 1), |
| + const StringQuoting($DQ, raw: false, leftQuoteLength: 1), |
| + const StringQuoting($DQ, raw: true, leftQuoteLength: 1), |
| + // No string quotes with 2 characters. |
| + null, |
| + null, |
| + null, |
| + null, |
| + const StringQuoting($SQ, raw: false, leftQuoteLength: 3), |
| + const StringQuoting($SQ, raw: true, leftQuoteLength: 3), |
| + const StringQuoting($DQ, raw: false, leftQuoteLength: 3), |
| + const StringQuoting($DQ, raw: true, leftQuoteLength: 3), |
| + // Leading single whitespace or espaped newline. |
| + const StringQuoting($SQ, raw: false, leftQuoteLength: 4), |
| + const StringQuoting($SQ, raw: true, leftQuoteLength: 4), |
| + const StringQuoting($DQ, raw: false, leftQuoteLength: 4), |
| + const StringQuoting($DQ, raw: true, leftQuoteLength: 4), |
| + // Other combinations of leading whitespace and/or escaped newline. |
| + const StringQuoting($SQ, raw: false, leftQuoteLength: 5), |
| + const StringQuoting($SQ, raw: true, leftQuoteLength: 5), |
| + const StringQuoting($DQ, raw: false, leftQuoteLength: 5), |
| + const StringQuoting($DQ, raw: true, leftQuoteLength: 5), |
| + const StringQuoting($SQ, raw: false, leftQuoteLength: 6), |
| + const StringQuoting($SQ, raw: true, leftQuoteLength: 6), |
| + const StringQuoting($DQ, raw: false, leftQuoteLength: 6), |
| + const StringQuoting($DQ, raw: true, leftQuoteLength: 6) |
| ]; |
| + |
| final bool raw; |
| final int leftQuoteCharCount; |
| final int quote; |
| @@ -888,9 +868,13 @@ class StringQuoting { |
| int get leftQuoteLength => (raw ? 1 : 0) + leftQuoteCharCount; |
| int get rightQuoteLength => (leftQuoteCharCount > 2) ? 3 : 1; |
| static StringQuoting getQuoting(int quote, bool raw, int quoteLength) { |
| + int quoteKindOffset = (quote == $DQ) ? 2 : 0; |
| + int rawOffset = raw ? 1 : 0; |
| int index = quoteLength - 1; |
|
Lasse Reichstein Nielsen
2014/06/18 09:05:32
Just multiply this by four immediately, instead of
floitsch
2014/06/18 12:14:23
Computing the full index now (including the rawOff
|
| - if (quoteLength > 2) index -= 1; |
| - return mapping[(raw ? 1 : 0) + index * 2 + (identical(quote, $SQ) ? 8 : 0)]; |
| + if (index * 4 < _mapping.length) { |
| + return _mapping[rawOffset + quoteKindOffset + index * 4]; |
| + } |
| + return new StringQuoting(quote, raw: raw, leftQuoteLength: index + 1); |
|
Lasse Reichstein Nielsen
2014/06/18 09:05:32
index + 1 -> quoteLength
floitsch
2014/06/18 12:14:23
doh.
done.
|
| } |
| } |