Skip to content

Commit bed3297

Browse files
committed
[libc++] Add ABI flag to make __tree nodes more compact
1 parent f1fc048 commit bed3297

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

libcxx/include/__configuration/abi.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@
116116
// This setting disables the addition of such artificial padding, leading to a more optimal
117117
// representation for several types.
118118
# define _LIBCPP_ABI_NO_COMPRESSED_PAIR_PADDING
119+
# define _LIBCPP_ABI_TREE_POINTER_INT_PAIR
119120
#elif _LIBCPP_ABI_VERSION == 1
120121
# if !(defined(_LIBCPP_OBJECT_FORMAT_COFF) || defined(_LIBCPP_OBJECT_FORMAT_XCOFF))
121122
// Enable compiling copies of now inline methods into the dylib to support
@@ -135,6 +136,8 @@
135136
# endif
136137
#endif
137138

139+
#define _LIBCPP_ABI_TREE_POINTER_INT_PAIR
140+
138141
// We had some bugs where we use [[no_unique_address]] together with construct_at,
139142
// which causes UB as the call on construct_at could write to overlapping subobjects
140143
//

libcxx/include/__tree

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

@@ -654,6 +655,45 @@ public:
654655
__tree_node_base& operator=(__tree_node_base const&) = delete;
655656
};
656657

658+
#ifdef _LIBCPP_ABI_TREE_POINTER_INT_PAIR
659+
template <>
660+
class __tree_node_base< void*> : public __tree_node_base_types<void*>::__end_node_type {
661+
using _NodeBaseTypes = __tree_node_base_types<void*>;
662+
663+
public:
664+
using pointer = typename _NodeBaseTypes::__node_base_pointer;
665+
using __parent_pointer = typename _NodeBaseTypes::__parent_pointer;
666+
667+
pointer __right_;
668+
669+
private:
670+
using __pair_t = __pointer_int_pair<__parent_pointer, bool, __integer_width(1)>;
671+
672+
__pair_t __parent_and_color_;
673+
674+
public:
675+
_LIBCPP_HIDE_FROM_ABI pointer __parent_unsafe() const {
676+
return static_cast<pointer>(__parent_and_color_.__get_ptr());
677+
}
678+
679+
_LIBCPP_HIDE_FROM_ABI void __set_parent(pointer __ptr) { __set_parent(static_cast<__parent_pointer>(__ptr)); }
680+
681+
_LIBCPP_HIDE_FROM_ABI void __set_parent(__parent_pointer __ptr) {
682+
__parent_and_color_ = __pair_t(__ptr, __parent_and_color_.__get_value());
683+
}
684+
685+
_LIBCPP_HIDE_FROM_ABI __parent_pointer __get_parent() const { return __parent_and_color_.__get_ptr(); }
686+
_LIBCPP_HIDE_FROM_ABI __tree_color __get_color() const {
687+
return static_cast<__tree_color>(__parent_and_color_.__get_value());
688+
}
689+
_LIBCPP_HIDE_FROM_ABI void __set_color(__tree_color __color) {
690+
__parent_and_color_ = __pair_t(__parent_and_color_.__get_ptr(), __color == __tree_color::__black);
691+
}
692+
};
693+
#endif // _LIBCPP_ABI_TREE_POINTER_INT_PAIR
694+
695+
static_assert(sizeof(__tree_node_base<void*>) == 24);
696+
657697
template <class _Tp, class _VoidPtr>
658698
class _LIBCPP_STANDALONE_DEBUG __tree_node : public __tree_node_base<_VoidPtr> {
659699
public:

0 commit comments

Comments
 (0)