[libcxx-commits] [libcxx] [libc++] Optimize vector growing of trivially relocatable types (PR #76657)
Amirreza Ashouri via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Jan 12 14:08:55 PST 2024
================
@@ -0,0 +1,100 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include <__type_traits/is_trivially_relocatable.h>
+#include <memory>
+#include <string>
+
+#include "constexpr_char_traits.h"
+#include "test_allocator.h"
+
+static_assert(std::__libcpp_is_trivially_relocatable<char>::value);
+static_assert(std::__libcpp_is_trivially_relocatable<int>::value);
+static_assert(std::__libcpp_is_trivially_relocatable<double>::value);
+
+struct Empty {};
+static_assert(std::__libcpp_is_trivially_relocatable<Empty>::value);
+
+struct TriviallyCopyable {
+ char c;
+ int i;
+ Empty s;
+};
+static_assert(std::__libcpp_is_trivially_relocatable<TriviallyCopyable>::value);
+
+struct NotTriviallyCopyable {
+ NotTriviallyCopyable(const NotTriviallyCopyable&);
+ ~NotTriviallyCopyable();
+};
+static_assert(!std::__libcpp_is_trivially_relocatable<NotTriviallyCopyable>::value);
+
+struct MoveOnlyTriviallyCopyable {
+ MoveOnlyTriviallyCopyable(const MoveOnlyTriviallyCopyable&) = delete;
+ MoveOnlyTriviallyCopyable& operator=(const MoveOnlyTriviallyCopyable&) = delete;
+ MoveOnlyTriviallyCopyable(MoveOnlyTriviallyCopyable&&) = default;
+ MoveOnlyTriviallyCopyable& operator=(MoveOnlyTriviallyCopyable&&) = default;
+};
+static_assert(std::__libcpp_is_trivially_relocatable<MoveOnlyTriviallyCopyable>::value);
+
+// standard library types
+// ----------------------
+
+// basic_string
+struct MyChar {
+ char c;
+};
+template <class T>
+struct NotTriviallyRelocatableCharTraits : constexpr_char_traits<T> {
+ NotTriviallyRelocatableCharTraits(const NotTriviallyRelocatableCharTraits&);
+ NotTriviallyRelocatableCharTraits& operator=(const NotTriviallyRelocatableCharTraits&);
+ ~NotTriviallyRelocatableCharTraits();
+};
+
+static_assert(std::__libcpp_is_trivially_relocatable<
+ std::basic_string<char, std::char_traits<char>, std::allocator<char>>>::value);
+static_assert(std::__libcpp_is_trivially_relocatable<
+ std::basic_string<char, NotTriviallyRelocatableCharTraits<char>, std::allocator<char>>>::value);
+static_assert(std::__libcpp_is_trivially_relocatable<
+ std::basic_string<MyChar, constexpr_char_traits<MyChar>, std::allocator<MyChar>>>::value);
+static_assert(std::__libcpp_is_trivially_relocatable<
+ std::basic_string<MyChar, NotTriviallyRelocatableCharTraits<MyChar>, std::allocator<MyChar>>>::value);
+static_assert(!std::__libcpp_is_trivially_relocatable<
+ std::basic_string<char, std::char_traits<char>, test_allocator<char>>>::value);
+static_assert(!std::__libcpp_is_trivially_relocatable<
+ std::basic_string<MyChar, NotTriviallyRelocatableCharTraits<MyChar>, test_allocator<MyChar>>>::value);
+
+// unique_ptr
+struct NotTriviallyRelocatableDeleter {
+ NotTriviallyRelocatableDeleter(const NotTriviallyRelocatableDeleter&);
+ NotTriviallyRelocatableDeleter& operator=(const NotTriviallyRelocatableDeleter&);
+ ~NotTriviallyRelocatableDeleter();
+
+ template <class T>
+ void operator()(T*);
+};
+
+struct NotTriviallyRelocatablePointer {
+ struct pointer {
+ pointer(const pointer&);
+ pointer& operator=(const pointer&);
+ ~pointer();
+ };
+
+ template <class T>
+ void operator()(T*);
----------------
AMP999 wrote:
Could this use `min_pointer` instead?" (from libcxx/test/support/)
https://github.com/llvm/llvm-project/pull/76657
More information about the libcxx-commits
mailing list