[PATCH] D25153: preprocessor supports `-dI` flag

Steve O'Brien via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 6 10:46:02 PDT 2016


elsteveogrande added inline comments.


> PrintPreprocessedOutput.cpp:329-330
> +static std::string sanitizePath(StringRef Path) {
> +  std::string Result;
> +  Result.reserve(Path.size() * 2);
> +  while (!Path.empty()) {

Note: I'm //pretty// sure this is about as efficient as it gets for string-building (and then also, string-builds will tend to happen only once per include).  The string has its internal char-vector-like structure, pre-sized to a generous amount, so extra futzing should not occur, making this `O(length of strings appended to it)`; and the return should optimize away so that it's not copied.

More importantly though, this is now quite a bit cleaner.

https://reviews.llvm.org/D25153





More information about the cfe-commits mailing list