Skip to content

Commit 4f3bb71

Browse files
authored
Refactor a List.generate to List.filled (flutter#87)
The meaning is more clear without the indirection of a closure that always returns the same value, and it will have better performance. Also replace the `List.insert` by making the length longer to start with and conditionally setting the first value.
1 parent 3e07d53 commit 4f3bb71

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

lib/src/parsed_path.dart

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,16 +128,12 @@ class ParsedPath {
128128
}
129129

130130
// Canonicalize separators.
131-
final newSeparators =
132-
List<String>.generate(newParts.length, (_) => style.separator);
133-
newSeparators.insert(
134-
0,
135-
isAbsolute && newParts.isNotEmpty && style.needsSeparator(root)
136-
? style.separator
137-
: '');
138-
139131
parts = newParts;
140-
separators = newSeparators;
132+
separators =
133+
List.filled(newParts.length + 1, style.separator, growable: true);
134+
if (!isAbsolute || newParts.isEmpty || !style.needsSeparator(root)) {
135+
separators[0] = '';
136+
}
141137

142138
// Normalize the Windows root if needed.
143139
if (root != null && style == Style.windows) {

0 commit comments

Comments
 (0)