Skip to content

Commit 920e834

Browse files
committed
[libc++] Add ABI flag to make __tree nodes more compact
1 parent 8e5e6f0 commit 920e834

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

libcxx/include/__configuration/abi.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
# define _LIBCPP_ABI_OPTIMIZED_FUNCTION
7676
# define _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO
7777
# define _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION
78+
# define _LIBCPP_ABI_TREE_POINTER_INT_PAIR
7879
# define _LIBCPP_ABI_USE_WRAP_ITER_IN_STD_ARRAY
7980
# define _LIBCPP_ABI_USE_WRAP_ITER_IN_STD_STRING_VIEW
8081
# define _LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION
@@ -98,6 +99,8 @@
9899
# endif
99100
#endif
100101

102+
#define _LIBCPP_ABI_TREE_POINTER_INT_PAIR
103+
101104
// We had some bugs where we use [[no_unique_address]] together with construct_at,
102105
// which causes UB as the call on construct_at could write to overlapping subobjects
103106
//

libcxx/include/__tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include <__utility/forward.h>
4242
#include <__utility/move.h>
4343
#include <__utility/pair.h>
44+
#include <__utility/pointer_int_pair.h>
4445
#include <__utility/swap.h>
4546
#include <limits>
4647

@@ -591,6 +592,43 @@ public:
591592
__tree_node_base& operator=(__tree_node_base const&) = delete;
592593
};
593594

595+
#ifdef _LIBCPP_ABI_TREE_POINTER_INT_PAIR
596+
template <>
597+
class __tree_node_base<void*> : public __tree_end_node<__tree_node_base<void*>*> {
598+
public:
599+
using pointer = __tree_node_base<void*>*;
600+
using __end_node_pointer _LIBCPP_NODEBUG = __tree_end_node<__tree_node_base<void*>*>*;
601+
602+
pointer __right_;
603+
604+
private:
605+
using __pair_t = __pointer_int_pair<__end_node_pointer, bool, __integer_width(1)>;
606+
607+
__pair_t __parent_and_color_;
608+
609+
public:
610+
_LIBCPP_HIDE_FROM_ABI pointer __parent_unsafe() const {
611+
return static_cast<pointer>(__parent_and_color_.__get_ptr());
612+
}
613+
614+
_LIBCPP_HIDE_FROM_ABI void __set_parent(pointer __ptr) { __set_parent(static_cast<__end_node_pointer>(__ptr)); }
615+
616+
_LIBCPP_HIDE_FROM_ABI void __set_parent(__end_node_pointer __ptr) {
617+
__parent_and_color_ = __pair_t(__ptr, __parent_and_color_.__get_value());
618+
}
619+
620+
_LIBCPP_HIDE_FROM_ABI __end_node_pointer __get_parent() const { return __parent_and_color_.__get_ptr(); }
621+
_LIBCPP_HIDE_FROM_ABI __tree_color __get_color() const {
622+
return static_cast<__tree_color>(__parent_and_color_.__get_value());
623+
}
624+
_LIBCPP_HIDE_FROM_ABI void __set_color(__tree_color __color) {
625+
__parent_and_color_ = __pair_t(__parent_and_color_.__get_ptr(), __color == __tree_color::__black);
626+
}
627+
};
628+
#endif // _LIBCPP_ABI_TREE_POINTER_INT_PAIR
629+
630+
static_assert(sizeof(__tree_node_base<void*>) == 24);
631+
594632
template <class _Tp, class _VoidPtr>
595633
class _LIBCPP_STANDALONE_DEBUG __tree_node : public __tree_node_base<_VoidPtr> {
596634
public:

0 commit comments

Comments
 (0)