Skip to content

Commit 46d64e6

Browse files
committed
Unconditionally change std::string's alignment to 8.
Save memory by providing the allocator more freedom to allocate the most efficient size class by dropping the alignment requirements for std::string's pointer from 16 to 8. This changes the output of std::string::max_size, which makes it ABI breaking. That said, the discussion concluded that we don't care about this ABI break and would like this change enabled universally
1 parent 1000cef commit 46d64e6

File tree

5 files changed

+6
-28
lines changed

5 files changed

+6
-28
lines changed

libcxx/include/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1044,7 +1044,7 @@ add_dependencies(cxx-headers generate-cxx-headers)
10441044
# It's important that the arch directory be included first so that its header files
10451045
# which interpose on the default include dir be included instead of the default ones.
10461046
target_include_directories(cxx-headers INTERFACE ${LIBCXX_GENERATED_INCLUDE_TARGET_DIR}
1047-
${LIBCXX_GENERATED_INCLUDE_DIR})
1047+
${CMAKE_CURRENT_LIST_DIR})
10481048

10491049
if (LIBCXX_INSTALL_HEADERS)
10501050
foreach(file ${files})

libcxx/include/__config

-5
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,6 @@
174174
// The implementation moved to the header, but we still export the symbols from
175175
// the dylib for backwards compatibility.
176176
# define _LIBCPP_ABI_DO_NOT_EXPORT_TO_CHARS_BASE_10
177-
// Save memory by providing the allocator more freedom to allocate the most
178-
// efficient size class by dropping the alignment requirements for std::string's
179-
// pointer from 16 to 8. This changes the output of std::string::max_size,
180-
// which makes it ABI breaking
181-
# define _LIBCPP_ABI_STRING_8_BYTE_ALIGNMENT
182177
# elif _LIBCPP_ABI_VERSION == 1
183178
# if !(defined(_LIBCPP_OBJECT_FORMAT_COFF) || defined(_LIBCPP_OBJECT_FORMAT_XCOFF))
184179
// Enable compiling copies of now inline methods into the dylib to support

libcxx/include/string

+1-6
Original file line numberDiff line numberDiff line change
@@ -1937,12 +1937,7 @@ private:
19371937
return (__s + (__a - 1)) & ~(__a - 1);
19381938
}
19391939
enum {
1940-
__alignment =
1941-
#ifdef _LIBCPP_ABI_STRING_8_BYTE_ALIGNMENT
1942-
8
1943-
#else
1944-
16
1945-
#endif
1940+
__alignment = 8
19461941
};
19471942
static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type __recommend(size_type __s) _NOEXCEPT {
19481943
if (__s < __min_cap) {

libcxx/test/libcxx/strings/basic.string/string.capacity/allocation_size.pass.cpp

+2-8
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,8 @@
1717

1818
#include "test_macros.h"
1919

20-
// alignment of the string heap buffer is hardcoded to either 16 or 8
21-
22-
const std::size_t alignment =
23-
#ifdef _LIBCPP_ABI_STRING_8_BYTE_ALIGNMENT
24-
8;
25-
#else
26-
16;
27-
#endif
20+
// alignment of the string heap buffer is hardcoded to 8
21+
const std::size_t alignment = 8;
2822

2923
int main(int, char**) {
3024
std::string input_string;

libcxx/test/libcxx/strings/basic.string/string.capacity/max_size.pass.cpp

+2-8
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,8 @@
1717

1818
#include "test_macros.h"
1919

20-
// alignment of the string heap buffer is hardcoded to 16
21-
22-
static const std::size_t alignment =
23-
#ifdef _LIBCPP_ABI_STRING_8_BYTE_ALIGNMENT
24-
8;
25-
#else
26-
16;
27-
#endif
20+
// alignment of the string heap buffer is hardcoded to 8
21+
static const std::size_t alignment = 8;
2822

2923
template <class = int>
3024
TEST_CONSTEXPR_CXX20 void full_size() {

0 commit comments

Comments
 (0)