[libcxx-commits] [libcxx] [libc++] Define deque::__block_size inline (PR #89422)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Fri Apr 19 10:47:14 PDT 2024


https://github.com/ldionne created https://github.com/llvm/llvm-project/pull/89422

We noticed that __block_size was sometimes generating weak-defs that were exported from programs. This is clearly unintended and unnecessary. Defining the constant inline should allow it to be inlined in the code all the time, which should help with that. It also simplifies the code.

>From 927ea9577a831cfe36fd391a03c4ccd9dab8294a Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Fri, 19 Apr 2024 13:43:35 -0400
Subject: [PATCH] [libc++] Define deque::__block_size inline

We noticed that __block_size was sometimes generating weak-defs that
were exported from programs. This is clearly unintended and unnecessary.
Defining the constant inline should allow it to be inlined in the code
all the time, which should help with that. It also simplifies the code.
---
 libcxx/include/deque | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)

diff --git a/libcxx/include/deque b/libcxx/include/deque
index d42669dd6dc0e1..c5562bba518b4a 100644
--- a/libcxx/include/deque
+++ b/libcxx/include/deque
@@ -276,7 +276,7 @@ private:
   __map_iterator __m_iter_;
   pointer __ptr_;
 
-  static const difference_type __block_size;
+  static _LIBCPP_CONSTEXPR const difference_type __block_size = __deque_block_size<_ValueType, _DiffType>::value;
 
 public:
   typedef _ValueType value_type;
@@ -438,10 +438,6 @@ public:
   }
 };
 
-template <class _ValueType, class _Pointer, class _Reference, class _MapPointer, class _DiffType, _DiffType _BlockSize>
-const _DiffType __deque_iterator<_ValueType, _Pointer, _Reference, _MapPointer, _DiffType, _BlockSize>::__block_size =
-    __deque_block_size<_ValueType, _DiffType>::value;
-
 template <class _Tp, class _Allocator /*= allocator<_Tp>*/>
 class _LIBCPP_TEMPLATE_VIS deque {
 public:
@@ -547,7 +543,7 @@ private:
     deque* const __base_;
   };
 
-  static const difference_type __block_size;
+  static _LIBCPP_CONSTEXPR const difference_type __block_size = __deque_block_size<_ValueType, _DiffType>::value;
 
   __map __map_;
   size_type __start_;
@@ -1194,10 +1190,6 @@ private:
   _LIBCPP_HIDE_FROM_ABI void __move_assign(deque& __c, false_type);
 };
 
-template <class _Tp, class _Alloc>
-_LIBCPP_CONSTEXPR const typename allocator_traits<_Alloc>::difference_type deque<_Tp, _Alloc>::__block_size =
-    __deque_block_size<value_type, difference_type>::value;
-
 #if _LIBCPP_STD_VER >= 17
 template <class _InputIterator,
           class _Alloc = allocator<__iter_value_type<_InputIterator>>,



More information about the libcxx-commits mailing list