[libcxx-commits] [PATCH] D75639: Partially inline basic_string copy constructor in UNSTABLE
Martijn Vels via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Mar 4 12:57:17 PST 2020
mvels created this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
mvels added a reviewer: EricWF.
Herald added a reviewer: mclow.lists.
This is a recommit of https://reviews.llvm.org/D73223 where the added function accidentally ended up inside an idef block.
This change splits the copy constructor up inlining short initialization, and explicitly outlining long initialization into __init_copy_ctor_external() which is the externally instantiated slow path.
For unstable ABI, this has the following changes:
remove basic_string(const basic_string&)
remove basic_string(const basic_string&, const Allocator&)
add __init_copy_ctor_external(const value_type*, size_type)
Quick local benchmark for Copy:
Master
---------------------------------------------------------------
Benchmark Time CPU Iterations
---------------------------------------------------------------
BM_StringCopy_Empty 3.50 ns 3.51 ns 199326720
BM_StringCopy_Small 3.50 ns 3.51 ns 199510016
BM_StringCopy_Large 15.7 ns 15.7 ns 45230080
BM_StringCopy_Huge 1503 ns 1503 ns 464896
With this change
---------------------------------------------------------------
Benchmark Time CPU Iterations
---------------------------------------------------------------
BM_StringCopy_Empty 1.99 ns 2.00 ns 356471808
BM_StringCopy_Small 3.29 ns 3.30 ns 203425792
BM_StringCopy_Large 13.3 ns 13.3 ns 52948992
BM_StringCopy_Huge 1472 ns 1472 ns 475136
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D75639
Files:
libcxx/include/string
Index: libcxx/include/string
===================================================================
--- libcxx/include/string
+++ libcxx/include/string
@@ -1894,6 +1894,25 @@
#endif
}
+template <class _CharT, class _Traits, class _Allocator>
+void basic_string<_CharT, _Traits, _Allocator>::__init_copy_ctor_external(
+ const value_type* __s, size_type __sz) {
+ pointer __p;
+ if (__sz < __min_cap) {
+ __p = __get_short_pointer();
+ __set_short_size(__sz);
+ } else {
+ if (__sz > max_size())
+ this->__throw_length_error();
+ size_t __cap = __recommend(__sz);
+ __p = __alloc_traits::allocate(__alloc(), __cap + 1);
+ __set_long_pointer(__p);
+ __set_long_cap(__cap + 1);
+ __set_long_size(__sz);
+ }
+ traits_type::copy(_VSTD::__to_address(__p), __s, __sz + 1);
+}
+
#ifndef _LIBCPP_CXX03_LANG
template <class _CharT, class _Traits, class _Allocator>
@@ -1914,25 +1933,6 @@
#endif
}
-template <class _CharT, class _Traits, class _Allocator>
-void basic_string<_CharT, _Traits, _Allocator>::__init_copy_ctor_external(
- const value_type* __s, size_type __sz) {
- pointer __p;
- if (__sz < __min_cap) {
- __p = __get_short_pointer();
- __set_short_size(__sz);
- } else {
- if (__sz > max_size())
- this->__throw_length_error();
- size_t __cap = __recommend(__sz);
- __p = __alloc_traits::allocate(__alloc(), __cap + 1);
- __set_long_pointer(__p);
- __set_long_cap(__cap + 1);
- __set_long_size(__sz);
- }
- traits_type::copy(_VSTD::__to_address(__p), __s, __sz + 1);
-}
-
template <class _CharT, class _Traits, class _Allocator>
inline
basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, const allocator_type& __a)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75639.248288.patch
Type: text/x-patch
Size: 1729 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20200304/d58a30ed/attachment.bin>
More information about the libcxx-commits
mailing list