[libcxx-commits] [PATCH] D116487: [libc++][NFC] Introduce __fits_in_sso()
Nikolas Klauser via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Jan 4 08:28:17 PST 2022
philnik updated this revision to Diff 397313.
philnik marked an inline comment as done.
philnik added a comment.
- Add comment to explain __libcpp_is_constant_evaluated() in __fits_in_sso()
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D116487/new/
https://reviews.llvm.org/D116487
Files:
libcxx/include/string
Index: libcxx/include/string
===================================================================
--- libcxx/include/string
+++ libcxx/include/string
@@ -1455,6 +1455,11 @@
#endif // _LIBCPP_DEBUG_LEVEL == 2
private:
+ _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI static bool __fits_in_sso(size_type __sz) {
+ // SSO is disabled during constant evaluation because `__is_long` isn't constexpr friendly
+ return !__libcpp_is_constant_evaluated() && (__sz < __min_cap);
+ }
+
_LIBCPP_INLINE_VISIBILITY
allocator_type& __alloc() _NOEXCEPT
{return __r_.second();}
@@ -1859,7 +1864,7 @@
if (__reserve > max_size())
this->__throw_length_error();
pointer __p;
- if (__reserve < __min_cap)
+ if (__fits_in_sso(__reserve))
{
__set_short_size(__sz);
__p = __get_short_pointer();
@@ -1883,7 +1888,7 @@
if (__sz > max_size())
this->__throw_length_error();
pointer __p;
- if (__sz < __min_cap)
+ if (__fits_in_sso(__sz))
{
__set_short_size(__sz);
__p = __get_short_pointer();
@@ -1975,7 +1980,7 @@
void basic_string<_CharT, _Traits, _Allocator>::__init_copy_ctor_external(
const value_type* __s, size_type __sz) {
pointer __p;
- if (__sz < __min_cap) {
+ if (__fits_in_sso(__sz)) {
__p = __get_short_pointer();
__set_short_size(__sz);
} else {
@@ -2042,7 +2047,7 @@
if (__n > max_size())
this->__throw_length_error();
pointer __p;
- if (__n < __min_cap)
+ if (__fits_in_sso(__n))
{
__set_short_size(__n);
__p = __get_short_pointer();
@@ -2194,7 +2199,7 @@
if (__sz > max_size())
this->__throw_length_error();
pointer __p;
- if (__sz < __min_cap)
+ if (__fits_in_sso(__sz))
{
__set_short_size(__sz);
__p = __get_short_pointer();
@@ -2398,7 +2403,7 @@
basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n)
{
_LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign received nullptr");
- return (__builtin_constant_p(__n) && __n < __min_cap)
+ return (__builtin_constant_p(__n) && __fits_in_sso(__n))
? __assign_short(__s, __n)
: __assign_external(__s, __n);
}
@@ -2601,7 +2606,7 @@
{
_LIBCPP_ASSERT(__s != nullptr, "string::assign received nullptr");
return __builtin_constant_p(*__s)
- ? (traits_type::length(__s) < __min_cap
+ ? (__fits_in_sso(traits_type::length(__s))
? __assign_short(__s, traits_type::length(__s))
: __assign_external(__s, traits_type::length(__s)))
: __assign_external(__s);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D116487.397313.patch
Type: text/x-patch
Size: 2718 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20220104/e8937569/attachment.bin>
More information about the libcxx-commits
mailing list