[libcxx-commits] [PATCH] D78763: Add optimization to basic_string::assign for compile-time known constant values.

Martijn Vels via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Thu Jun 18 12:34:34 PDT 2020


mvels marked 2 inline comments as done.
mvels added inline comments.


================
Comment at: libcxx/include/string:2306
     _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign received nullptr");
-    return (__builtin_constant_p(__n) && __n <= 128 / sizeof(value_type))
-               ? __assign_small_length(__s, __n)
+    return (_LIBCPP_BUILTIN_CONSTANT_P(__n) && __n < __min_cap)
+               ? __assign_short(__s, __n)
----------------
ldionne wrote:
> It used to be `__n <= ...`, now it's `__n < ...` -- what am I missing?
The initial version was aimed at optimizing 2 things:
- short optimization, i.e., [n] chars < min_cap guaranteed to fit inside any SSO or heap allocated string
- small memcpy optimization, i.., n <= 128 which when inlined can be vectorized efficiently (i.e., a rough max memcpy inline)

For this change we should focus only on the former. The latter is better picked up as an FDO / LLVM compiler inlining opportunity.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78763





More information about the libcxx-commits mailing list