Repository: carbon-language/carbon-lang
File: toolchain/driver/compile_subcommand.cpp (C++)

Code before:
    if (include_in_dumps_.empty()) {
      BuildIncludeInDumps();
    }
    return include_in_dumps_;
  }

  auto tree_and_subtrees_getters()
      -> llvm::ArrayRef<Parse::GetTreeAndSubtreesFn> {
    CARBON_CHECK(!units_.empty());
    if (tree_and_subtrees_getters_.empty()) {
      BuildTreeAndSubtreesGetters();
    }
    return tree_and_subtrees_getters_;
  }

 private:
  auto BuildIncludeInDumps() -> void {
    CARBON_CHECK(include_in_dumps_.empty());
    llvm::append_range(
        include_in_dumps_, llvm::map_range(units_, [&](const auto& unit) {
          for (auto prefix : options_->exclude_dump_file_prefixes) {
            if (unit->input_filename().starts_with(prefix)) {
              return false;
            }
          }
          return true;
        }));
  }

  auto BuildTreeAndSubtreesGetters() -> void {
    CARBON_CHECK(tree_and_subtrees_getters_.empty());
    llvm::append_range(
        tree_and_subtrees_getters_,
        llvm::map_range(units_, [&](const auto& unit) {
          return unit->has_source() ? unit->get_trees_and_subtrees() : nullptr;
        }));
  }

  const CompileOptions* options_;

  // The units being compiled.
  const llvm::ArrayRef<std::unique_ptr<CompilationUnit>> units_;

  // For each unit, whether it's included in dumps. Used cross-phase.
  llvm::SmallVector<bool> include_in_dumps_;

  // For each unit, the `TreeAndSubtrees` getter. Used by lowering.
  llvm::SmallVector<Parse::GetTreeAndSubtreesFn> tree_and_subtrees_getters_;
};

}  // namespace

Review comment (suggestion):
Could write this as:
```
return llvm::none_of(options_->exclude_dump_file_prefixes, [&](auto prefix) { return unit->inut_filename().starts_with(prefix); });
```
I sometimes find the predicate form a bit more readable, but it's certainly marginal/debateable.

Code after:
    if (include_in_dumps_.empty()) {
      BuildIncludeInDumps();
    }
    return include_in_dumps_;
  }

  auto tree_and_subtrees_getters()
      -> llvm::ArrayRef<Parse::GetTreeAndSubtreesFn> {
    CARBON_CHECK(!units_.empty());
    if (tree_and_subtrees_getters_.empty()) {
      BuildTreeAndSubtreesGetters();
    }
    return tree_and_subtrees_getters_;
  }

 private:
  auto BuildIncludeInDumps() -> void {
    CARBON_CHECK(include_in_dumps_.empty());
    llvm::append_range(
        include_in_dumps_, llvm::map_range(units_, [&](const auto& unit) {
          return llvm::none_of(
              options_->exclude_dump_file_prefixes, [&](auto prefix) {
                return unit->input_filename().starts_with(prefix);
              });
        }));
  }

  auto BuildTreeAndSubtreesGetters() -> void {
    CARBON_CHECK(tree_and_subtrees_getters_.empty());
    llvm::append_range(
        tree_and_subtrees_getters_,
        llvm::map_range(units_, [&](const auto& unit) {
          return unit->has_source() ? unit->get_trees_and_subtrees() : nullptr;
        }));
  }

  const CompileOptions* options_;

  // The units being compiled.
  const llvm::ArrayRef<std::unique_ptr<CompilationUnit>> units_;

  // For each unit, whether it's included in dumps. Used cross-phase.
  llvm::SmallVector<bool> include_in_dumps_;

  // For each unit, the `TreeAndSubtrees` getter. Used by lowering.
  llvm::SmallVector<Parse::GetTreeAndSubtreesFn> tree_and_subtrees_getters_;
};

}  // namespace

CompilationUnit::CompilationUnit(int unit_index, DriverEnv* driver_env,