Skip to content

Commit 7966a06

Browse files
refactor(path): use null-aware elements in join and absolute
Replace list-based argument validation with individual parameter validation to avoid list allocation overhead. Use Dart 3.8 null-aware elements (?expr) in list literals to build filtered lists directly instead of using whereType<String>(). - Add _validateArgs() that operates on 16 String? arguments directly - Add _throwArgError() helper for constructing error messages - Update join() and absolute() to use null-aware elements - Bump SDK constraint to ^3.8.0 Performance improvement: ~2x faster for absolute() operations.
1 parent 83154f2 commit 7966a06

3 files changed

Lines changed: 506 additions & 45 deletions

File tree

pkgs/path/benchmark/benchmark.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ void main(List<String> args) {
5858
}
5959

6060
benchmark('absolute', context.absolute);
61+
runBenchmark('${style.name}-join', 100000, () {
62+
for (var file in files) {
63+
context.join(file, 'subdir', 'file.txt');
64+
}
65+
});
66+
runBenchmark('${style.name}-join-many', 100000, () {
67+
for (var file in files) {
68+
context.join(file, 'a', 'b', 'c', 'd', 'e', 'f');
69+
}
70+
});
6171
benchmark('basename', context.basename);
6272
benchmark('basenameWithoutExtension', context.basenameWithoutExtension);
6373
benchmark('dirname', context.dirname);

0 commit comments

Comments
 (0)