Skip to content

Commit a410e62

Browse files
committed
Add missing BOOST_IF_CONSTEXPR for constant conditions
1 parent e46f1e7 commit a410e62

2 files changed

Lines changed: 29 additions & 27 deletions

File tree

include/boost/interprocess/allocators/detail/allocator_common.hpp

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,7 @@ class cache_impl
255255
if(m_cached_nodes.empty()){
256256
mp_node_pool->allocate_nodes(m_max_cached_nodes/2, m_cached_nodes);
257257
}
258-
void *ret = ipcdetail::to_raw_pointer(m_cached_nodes.pop_front());
259-
return ret;
258+
return ipcdetail::to_raw_pointer(m_cached_nodes.pop_front());
260259
}
261260

262261
void cached_allocation(size_type n, multiallocation_chain &chain)
@@ -540,14 +539,14 @@ class node_pool_allocation_impl
540539
if(size_overflows<sizeof(T)>(count)){
541540
throw bad_alloc();
542541
}
543-
else if(Version == 1 && count == 1){
544-
return pointer(static_cast<value_type*>
545-
(pool->allocate_node()));
546-
}
547-
else{
548-
return pointer(static_cast<value_type*>
549-
(pool->get_segment_manager()->allocate_aligned(count*sizeof(T), boost::container::dtl::alignment_of<T>::value)));
542+
543+
BOOST_IF_CONSTEXPR(Version == 1)
544+
if(count == 1){
545+
return pointer(static_cast<value_type*>(pool->allocate_node()));
550546
}
547+
548+
return pointer(static_cast<value_type*>
549+
(pool->get_segment_manager()->allocate_aligned(count*sizeof(T), boost::container::dtl::alignment_of<T>::value)));
551550
}
552551

553552
//!Deallocate allocated memory. Never throws
@@ -556,10 +555,14 @@ class node_pool_allocation_impl
556555
(void)count;
557556
typedef typename node_pool<0>::type node_pool_t;
558557
node_pool_t *pool = node_pool<0>::get(this->derived()->get_node_pool());
559-
if(Version == 1 && count == 1)
558+
559+
BOOST_IF_CONSTEXPR(Version == 1)
560+
if(count == 1){
560561
pool->deallocate_node(ipcdetail::to_raw_pointer(ptr));
561-
else
562-
pool->get_segment_manager()->deallocate((void*)ipcdetail::to_raw_pointer(ptr));
562+
return;
563+
}
564+
565+
pool->get_segment_manager()->deallocate((void*)ipcdetail::to_raw_pointer(ptr));
563566
}
564567

565568
//!Allocates just one object. Memory allocated with this function
@@ -729,30 +732,29 @@ class cached_allocator_impl
729732
BOOST_INTERPROCESS_NODISCARD
730733
pointer allocate(size_type count)
731734
{
732-
void * ret;
733735
if(size_overflows<sizeof(T)>(count)){
734736
throw bad_alloc();
735737
}
736-
else if(Version == 1 && count == 1){
737-
ret = m_cache.cached_allocation();
738-
}
739-
else{
740-
ret = this->get_segment_manager()->allocate_aligned
741-
(count*sizeof(T), boost::container::dtl::alignment_of<T>::value);
738+
739+
BOOST_IF_CONSTEXPR(Version == 1)
740+
if(count == 1){
741+
return pointer(static_cast<T*>(m_cache.cached_allocation()));
742742
}
743-
return pointer(static_cast<T*>(ret));
743+
744+
return pointer(static_cast<value_type*>
745+
(this->get_segment_manager()->allocate_aligned(count*sizeof(T), boost::container::dtl::alignment_of<T>::value)));
744746
}
745747

746748
//!Deallocate allocated memory. Never throws
747749
void deallocate(const pointer &ptr, size_type count)
748750
{
749751
(void)count;
750-
if(Version == 1 && count == 1){
752+
BOOST_IF_CONSTEXPR(Version == 1)
753+
if (count == 1) {
751754
m_cache.cached_deallocation(ipcdetail::to_raw_pointer(ptr));
755+
return;
752756
}
753-
else{
754-
this->get_segment_manager()->deallocate((void*)ipcdetail::to_raw_pointer(ptr));
755-
}
757+
this->get_segment_manager()->deallocate((void*)ipcdetail::to_raw_pointer(ptr));
756758
}
757759

758760
//!Allocates just one object. Memory allocated with this function

include/boost/interprocess/detail/windows_intermodule_singleton.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class windows_semaphore_based_map
7272
//those values can't be negative, so we have 31 bits to store something
7373
//in max_count and initial count parameters.
7474
//Also, max count must be bigger than 0 and bigger or equal than initial count.
75-
if(sizeof(void*) == sizeof(boost::uint32_t)){
75+
BOOST_IF_CONSTEXPR(sizeof(void*) == sizeof(boost::uint32_t)){
7676
//This means that for 32 bit processes, a semaphore count (31 usable bits) is
7777
//enough to store 4 byte aligned memory (4GB -> 32 bits - 2 bits = 30 bits).
7878
//The max count will hold the pointer value and current semaphore count
@@ -90,7 +90,7 @@ class windows_semaphore_based_map
9090
BOOST_ASSERT((caster.addr_uint32 & boost::uint32_t(3)) == 0);
9191
max_count = caster.addr_uint32 >> 2;
9292
}
93-
else if(sizeof(void*) == sizeof(boost::uint64_t)){
93+
else BOOST_IF_CONSTEXPR(sizeof(void*) == sizeof(boost::uint64_t)){
9494
//Relying in UB with a cast through union, but all known windows compilers
9595
//accept this (C11 accepts this).
9696
union caster_union
@@ -156,7 +156,7 @@ class windows_semaphore_based_map
156156

157157
map_type &get_map_unlocked()
158158
{
159-
if(sizeof(void*) == sizeof(boost::uint32_t)){
159+
BOOST_IF_CONSTEXPR(sizeof(void*) == sizeof(boost::uint32_t)){
160160
union caster_union
161161
{
162162
void *addr;

0 commit comments

Comments
 (0)