[PATCH] D12355: [libcxx] Optimize away unneeded length calculation in basic_string::compare(const char*)
Eric Fiselier via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 27 15:45:18 PDT 2015
EricWF marked an inline comment as done.
================
Comment at: include/string:3802
@@ -3799,2 +3801,3 @@
+ return _Traits::compare(__rhs.data(), __lhs, _VSTD::min(__lhs_len, __rhs.size())) == 0;
}
----------------
mclow.lists wrote:
> Also, you should not call `traits::compare` here. You should call `__rhs.compare(0, npos, __lhs, __lhs_len)`
>
> which is what `__rhs.compare(__lhs)` does.
>
I actually don't want to invoke `compare` because it has different semantics and does unneeded work. `compare` first does a comparison using `traits::compare` and then does a comparison using `length`. We have already compared based on length and we don't need to do any of the extra work that `compare(...)` does. I think calling `__rhs.compare(0, npos, __lhs, __lhs_len)` would be a pessimization.
http://reviews.llvm.org/D12355
More information about the cfe-commits
mailing list