Chromium Code Reviews| Index: pkg/path/lib/src/parsed_path.dart |
| diff --git a/pkg/path/lib/src/parsed_path.dart b/pkg/path/lib/src/parsed_path.dart |
| index 3f3c3b9cb645bec066b10b884cdff8e2cdf1b461..8bb26d6923414421fd5e4a4ef215a930c9257e13 100644 |
| --- a/pkg/path/lib/src/parsed_path.dart |
| +++ b/pkg/path/lib/src/parsed_path.dart |
| @@ -52,19 +52,20 @@ class ParsedPath { |
| var parts = []; |
| var separators = []; |
| - var firstSeparator = style.separatorPattern.matchAsPrefix(path); |
| - if (firstSeparator != null) { |
| - separators.add(firstSeparator[0]); |
| - path = path.substring(firstSeparator[0].length); |
| - } else { |
| - separators.add(''); |
| - } |
| + var firstSeparator = style.separators.firstWhere(path.startsWith, |
|
Bob Nystrom
2014/06/02 22:43:05
I got a noticeable speed bump (1.61s -> 1.37s) by
nweiz
2014/06/02 23:13:25
Done, with a little less code duplication.
|
| + orElse: () => ''); |
| + separators.add(firstSeparator); |
| + path = path.substring(firstSeparator.length); |
| var start = 0; |
| - for (var match in style.separatorPattern.allMatches(path)) { |
| - parts.add(path.substring(start, match.start)); |
| - separators.add(match[0]); |
| - start = match.end; |
| + for (var i = 0; i < path.length; i++) { |
| + for (var separator in style.separators) { |
| + if (path[i] == separator) { |
| + parts.add(path.substring(start, i)); |
| + separators.add(separator); |
| + start = i + 1; |
| + } |
| + } |
| } |
| // Add the final part, if any. |
| @@ -133,8 +134,7 @@ class ParsedPath { |
| var newSeparators = new List.generate( |
| newParts.length, (_) => style.separator, growable: true); |
| newSeparators.insert(0, |
| - isAbsolute && newParts.length > 0 && |
| - root.contains(style.needsSeparatorPattern) ? |
| + isAbsolute && newParts.length > 0 && style.needsSeparator(root) ? |
| style.separator : ''); |
| parts = newParts; |