Small cleanup on single set add (dart-lang/glob#29) - Add generic type on Set constructor. - Use `??=` for null defaulting. - Avoid the extra `set.contains` check since `set.add` already returns a bool indicating if the element is new.
diff --git a/pkgs/glob/lib/src/list_tree.dart b/pkgs/glob/lib/src/list_tree.dart index 8a23b1c..0572382 100644 --- a/pkgs/glob/lib/src/list_tree.dart +++ b/pkgs/glob/lib/src/list_tree.dart
@@ -169,7 +169,7 @@ /// List all entities that match this glob beneath [root]. Stream<FileSystemEntity> list({String root, bool followLinks = true}) { - if (root == null) root = '.'; + root ??= '.'; var group = StreamGroup<FileSystemEntity>(); for (var rootDir in _trees.keys) { var dir = rootDir == '.' ? root : rootDir; @@ -179,20 +179,15 @@ if (!_canOverlap) return group.stream; - // TODO(nweiz): Rather than filtering here, avoid double-listing directories + // TODO: Rather than filtering here, avoid double-listing directories // in the first place. - var seen = Set(); - return group.stream.where((entity) { - if (seen.contains(entity.path)) return false; - seen.add(entity.path); - return true; - }); + var seen = Set<String>(); + return group.stream.where((entity) => seen.add(entity.path)); } /// Synchronosuly list all entities that match this glob beneath [root]. List<FileSystemEntity> listSync({String root, bool followLinks = true}) { - if (root == null) root = '.'; - + root ??= '.'; var result = _trees.keys.expand((rootDir) { var dir = rootDir == '.' ? root : rootDir; return _trees[rootDir].listSync(dir, followLinks: followLinks); @@ -200,14 +195,10 @@ if (!_canOverlap) return result.toList(); - // TODO(nweiz): Rather than filtering here, avoid double-listing directories + // TODO: Rather than filtering here, avoid double-listing directories // in the first place. var seen = Set<String>(); - return result.where((entity) { - if (seen.contains(entity.path)) return false; - seen.add(entity.path); - return true; - }).toList(); + return result.where((entity) => seen.add(entity.path)).toList(); } }
diff --git a/pkgs/glob/pubspec.yaml b/pkgs/glob/pubspec.yaml index bc7f6af..f2c65e5 100644 --- a/pkgs/glob/pubspec.yaml +++ b/pkgs/glob/pubspec.yaml
@@ -1,5 +1,5 @@ name: glob -version: 1.2.0 +version: 1.2.1-dev description: Bash-style filename globbing. author: Dart Team <misc@dartlang.org>