Skip to content

Commit 3b64a20

Browse files
Refactor: Improve list generation in _generatePathological
Refine the list creation to be more explicit and performant. - Use a more descriptive name `sortedBase` instead of `base`. - Create the initial `sortedBase` list with `growable: false` as it is never modified. - Use `List.of` and explicitly set `growable: true` for the final copies to make the intent clear that they are mutable.
1 parent 660314a commit 3b64a20

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

pkgs/collection/benchmark/dataset_generator.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ List<List<int>> _generateFewUnique() {
4040
}
4141

4242
List<List<int>> _generatePathological() {
43-
final base = List.generate(size, (i) => i);
43+
final sortedBase = List.generate(size, (i) => i, growable: false);
4444
// Creates a "V-shape" or "organ pipe" array that can be challenging
4545
// for quicksort implementations by promoting unbalanced partitions.
4646
final pathological = <int>[
47-
for (int i = 0; i < size; i++)
48-
if (i.isEven) base[i],
49-
for (int i = size - 1; i > 0; i--)
50-
if (i.isOdd) base[i],
47+
for (var i = 0; i < size; i++)
48+
if (i.isEven) sortedBase[i],
49+
for (var i = size - 1; i > 0; i--)
50+
if (i.isOdd) sortedBase[i],
5151
];
52-
return List.generate(count, (_) => List<int>.from(pathological));
52+
return List.generate(count, (_) => List.of(pathological, growable: true));
5353
}

0 commit comments

Comments
 (0)