[cfe-commits] [PATCH] StringRef'ize API: clang::Token::getName()

Jordy Rose jediknil at belkadan.com
Mon Jun 27 20:50:07 PDT 2011

On Jun 27, 2011, at 19:32, John McCall wrote:

> On Jun 27, 2011, at 5:14 PM, Chris Lattner wrote:
>> This is a great start, but I'd prefer to not change these: if they aren't called at all, please send in a patch to nuke them :).  Also, since these are just returning constant C strings, a "const char*" is actually good enough.
> Surely all of the callers of getName() would have to do an unnecessary strlen here?  Granted that there aren't any. :)  But if we weren't nuking the calls, I don't see why converting them to return StringRef wouldn't be an improvement.
> John

One possible difference is that if all accesses go through the same functions, you could compare the strings using ==. Also, cases where a token is only printed under certain circumstances might be able to avoid the minor cost of constructing or copy-constructing StringRefs that may not even be used. (But the cost of strlen probably adds up faster than the cost of copy-constructor, and both are pretty minimal on non-hot code paths.)


More information about the cfe-commits mailing list