[cfe-commits] r160265 - in /cfe/trunk: include/clang/Tooling/CommandLineClangTool.h lib/Tooling/CMakeLists.txt lib/Tooling/CommandLineClangTool.cpp test/CMakeLists.txt test/Tooling/clang-ast-dump.cpp tools/CMakeLists.txt tools/Makefile tools/clan

Jordan Rose jordan_rose at apple.com
Thu Jul 26 08:20:31 PDT 2012


On Jul 26, 2012, at 3:59 AM, Alexander Kornienko <alexfh at google.com> wrote:

> >> -ASTConsumer *CreateASTPrinter(raw_ostream *OS);
> >> +ASTConsumer *CreateASTPrinter(raw_ostream *OS, const std::string
> >> &FilterString);
> >>
> >> Any reasons not to use StringRef?
> >
> > The reason is that performance issues are not going to appear in this code,
> > which is invoked once per program execution.
> 
>> My impression is that Clang has a "use StringRef unless you have a
>> good reason not to". With that in place, not using StringRef makes
>> readers of the code stop and think why you did it.
> 
> I didn't find this specific rule, but there's no reason not to believe your words yet ;) Changed interface to use StringRef.

We should probably update the Programmers' Manual here; this is the general rule these days. At the very least, StringRef can be used with SmallString as well, while std::string only has a conversion from plain C strings and other std::strings. And even in non-critical code, it's nice to save a malloc, copy, and free basically without cost.



More information about the cfe-commits mailing list