[libcxx-commits] [PATCH] D59999: Allow the compiler to optimize `string == "literal string"`.

Samuel Benzaquen via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Wed May 8 07:52:59 PDT 2019


sbenza added a comment.

In D59999#1494991 <https://reviews.llvm.org/D59999#1494991>, @mclow.lists wrote:

> I'm not happy with this. In particular, it does NOT call through the character traits, which it is required to do by the standard.


Doesn't this fall under the as-if? There should not be a way for well behaved code to know the difference. They can't specialize `char_traits<char>`, they can't specialize `basic_string<char, char_traits<char>, allocator<char>>`.

I can go through the char_traits, but `char_traits::compare()` has an extra branch that is unnecessary here. `compare` checks that the size is not 0, which is useful to avoid calling `memcmp` with null pointers. But there is no possiblity of null pointers here. The `.data()` will never return null, and the `char*` can't be null either (there is an assertion for that, and we passed it to `strlen`).

Can you offer a solution?
It is not good for the user to have all that code bloat and runtime cost when doing something as simple as `== ""`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D59999/new/

https://reviews.llvm.org/D59999





More information about the libcxx-commits mailing list