Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library path.parsed_path; | 5 library path.parsed_path; |
| 6 | 6 |
| 7 import 'internal_style.dart'; | 7 import 'internal_style.dart'; |
| 8 import 'style.dart'; | 8 import 'style.dart'; |
| 9 | 9 |
| 10 class ParsedPath { | 10 class ParsedPath { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 45 | 45 |
| 46 // Remove the root prefix, if any. | 46 // Remove the root prefix, if any. |
| 47 var root = style.getRoot(path); | 47 var root = style.getRoot(path); |
| 48 var isRootRelative = style.getRelativeRoot(path) != null; | 48 var isRootRelative = style.getRelativeRoot(path) != null; |
| 49 if (root != null) path = path.substring(root.length); | 49 if (root != null) path = path.substring(root.length); |
| 50 | 50 |
| 51 // Split the parts on path separators. | 51 // Split the parts on path separators. |
| 52 var parts = []; | 52 var parts = []; |
| 53 var separators = []; | 53 var separators = []; |
| 54 | 54 |
| 55 var firstSeparator = style.separatorPattern.matchAsPrefix(path); | 55 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.
| |
| 56 if (firstSeparator != null) { | 56 orElse: () => ''); |
| 57 separators.add(firstSeparator[0]); | 57 separators.add(firstSeparator); |
| 58 path = path.substring(firstSeparator[0].length); | 58 path = path.substring(firstSeparator.length); |
| 59 } else { | |
| 60 separators.add(''); | |
| 61 } | |
| 62 | 59 |
| 63 var start = 0; | 60 var start = 0; |
| 64 for (var match in style.separatorPattern.allMatches(path)) { | 61 for (var i = 0; i < path.length; i++) { |
| 65 parts.add(path.substring(start, match.start)); | 62 for (var separator in style.separators) { |
| 66 separators.add(match[0]); | 63 if (path[i] == separator) { |
| 67 start = match.end; | 64 parts.add(path.substring(start, i)); |
| 65 separators.add(separator); | |
| 66 start = i + 1; | |
| 67 } | |
| 68 } | |
| 68 } | 69 } |
| 69 | 70 |
| 70 // Add the final part, if any. | 71 // Add the final part, if any. |
| 71 if (start < path.length) { | 72 if (start < path.length) { |
| 72 parts.add(path.substring(start)); | 73 parts.add(path.substring(start)); |
| 73 separators.add(''); | 74 separators.add(''); |
| 74 } | 75 } |
| 75 | 76 |
| 76 return new ParsedPath._(style, root, isRootRelative, parts, separators); | 77 return new ParsedPath._(style, root, isRootRelative, parts, separators); |
| 77 } | 78 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 126 | 127 |
| 127 // If we collapsed down to nothing, do ".". | 128 // If we collapsed down to nothing, do ".". |
| 128 if (newParts.length == 0 && !isAbsolute) { | 129 if (newParts.length == 0 && !isAbsolute) { |
| 129 newParts.add('.'); | 130 newParts.add('.'); |
| 130 } | 131 } |
| 131 | 132 |
| 132 // Canonicalize separators. | 133 // Canonicalize separators. |
| 133 var newSeparators = new List.generate( | 134 var newSeparators = new List.generate( |
| 134 newParts.length, (_) => style.separator, growable: true); | 135 newParts.length, (_) => style.separator, growable: true); |
| 135 newSeparators.insert(0, | 136 newSeparators.insert(0, |
| 136 isAbsolute && newParts.length > 0 && | 137 isAbsolute && newParts.length > 0 && style.needsSeparator(root) ? |
| 137 root.contains(style.needsSeparatorPattern) ? | |
| 138 style.separator : ''); | 138 style.separator : ''); |
| 139 | 139 |
| 140 parts = newParts; | 140 parts = newParts; |
| 141 separators = newSeparators; | 141 separators = newSeparators; |
| 142 | 142 |
| 143 // Normalize the Windows root if needed. | 143 // Normalize the Windows root if needed. |
| 144 if (root != null && style == Style.windows) { | 144 if (root != null && style == Style.windows) { |
| 145 root = root.replaceAll('/', '\\'); | 145 root = root.replaceAll('/', '\\'); |
| 146 } | 146 } |
| 147 removeTrailingSeparators(); | 147 removeTrailingSeparators(); |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 177 if (lastDot <= 0) return [file, '']; | 177 if (lastDot <= 0) return [file, '']; |
| 178 | 178 |
| 179 return [file.substring(0, lastDot), file.substring(lastDot)]; | 179 return [file.substring(0, lastDot), file.substring(lastDot)]; |
| 180 } | 180 } |
| 181 | 181 |
| 182 ParsedPath clone() => new ParsedPath._( | 182 ParsedPath clone() => new ParsedPath._( |
| 183 style, root, isRootRelative, | 183 style, root, isRootRelative, |
| 184 new List.from(parts), new List.from(separators)); | 184 new List.from(parts), new List.from(separators)); |
| 185 } | 185 } |
| 186 | 186 |
| OLD | NEW |