Refactor a List.generate to List.filled (#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.
diff --git a/lib/src/parsed_path.dart b/lib/src/parsed_path.dart
index 8d96cd5..799a3bb 100644
--- a/lib/src/parsed_path.dart
+++ b/lib/src/parsed_path.dart
@@ -128,16 +128,12 @@
}
// Canonicalize separators.
- final newSeparators =
- List<String>.generate(newParts.length, (_) => style.separator);
- newSeparators.insert(
- 0,
- isAbsolute && newParts.isNotEmpty && style.needsSeparator(root)
- ? style.separator
- : '');
-
parts = newParts;
- separators = newSeparators;
+ separators =
+ List.filled(newParts.length + 1, style.separator, growable: true);
+ if (!isAbsolute || newParts.isEmpty || !style.needsSeparator(root)) {
+ separators[0] = '';
+ }
// Normalize the Windows root if needed.
if (root != null && style == Style.windows) {