Skip to content

Commit 2a6899d

Browse files
committed
temp
1 parent 3ab921f commit 2a6899d

1 file changed

Lines changed: 19 additions & 18 deletions

File tree

include/boost/json/storage_ptr.hpp

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,9 @@ class storage_ptr
8888
shared_resource*
8989
get_shared() const noexcept
9090
{
91-
auto const i = reinterpret_cast<std::uintptr_t>(p_);
92-
auto const c_ptr = reinterpret_cast<unsigned char*>(p_) - (i & 3);
91+
auto const i = reinterpret_cast<std::uintptr_t>(p_) & ~3;
9392
return static_cast<shared_resource*>(
94-
reinterpret_cast<container::pmr::memory_resource*>(c_ptr));
93+
reinterpret_cast<container::pmr::memory_resource*>(i));
9594
}
9695

9796
void
@@ -117,9 +116,10 @@ class storage_ptr
117116
template<class T>
118117
storage_ptr(
119118
detail::shared_resource_impl<T>* p) noexcept
120-
: p_(reinterpret_cast<unsigned char*>(
121-
static_cast<container::pmr::memory_resource*>(p))
122-
+ 1 + (json::is_deallocate_trivial<T>::value ? 2 : 0))
119+
: p_(reinterpret_cast<void*>(
120+
reinterpret_cast<std::uintptr_t>(
121+
static_cast<container::pmr::memory_resource*>(p))
122+
+ 1 + (json::is_deallocate_trivial<T>::value ? 2 : 0)))
123123
{
124124
BOOST_ASSERT(p);
125125
}
@@ -202,9 +202,10 @@ class storage_ptr
202202
#endif
203203
>
204204
storage_ptr(T* r) noexcept
205-
: p_(reinterpret_cast<unsigned char*>(
206-
static_cast<container::pmr::memory_resource*>(r))
207-
+ (json::is_deallocate_trivial<T>::value ? 2 : 0))
205+
: p_(reinterpret_cast<void*>(
206+
reinterpret_cast<std::uintptr_t>(
207+
static_cast<container::pmr::memory_resource*>(r))
208+
+ (json::is_deallocate_trivial<T>::value ? 2 : 0)))
208209
{
209210
BOOST_ASSERT(r);
210211
}
@@ -300,7 +301,7 @@ class storage_ptr
300301
bool
301302
is_shared() const noexcept
302303
{
303-
auto i = reinterpret_cast<std::uintptr_t>(p_);
304+
auto const i = reinterpret_cast<std::uintptr_t>(p_);
304305
return (i & 1) != 0;
305306
}
306307

@@ -314,7 +315,7 @@ class storage_ptr
314315
bool
315316
is_deallocate_trivial() const noexcept
316317
{
317-
auto i = reinterpret_cast<std::uintptr_t>(p_);
318+
auto const i = reinterpret_cast<std::uintptr_t>(p_);
318319
return (i & 2) != 0;
319320
}
320321

@@ -327,7 +328,7 @@ class storage_ptr
327328
bool
328329
is_not_shared_and_deallocate_is_trivial() const noexcept
329330
{
330-
auto i = reinterpret_cast<std::uintptr_t>(p_);
331+
auto const i = reinterpret_cast<std::uintptr_t>(p_);
331332
return (i & 3) == 2;
332333
}
333334

@@ -345,12 +346,12 @@ class storage_ptr
345346
container::pmr::memory_resource*
346347
get() const noexcept
347348
{
348-
if(!p_)
349-
return default_resource::get();
350-
351-
auto const i = reinterpret_cast<std::uintptr_t>(p_);
352-
auto const c_ptr = reinterpret_cast<unsigned char*>(p_) - (i & 3);
353-
return reinterpret_cast<container::pmr::memory_resource*>(c_ptr);
349+
if(p_)
350+
{
351+
auto const i = reinterpret_cast<std::uintptr_t>(p_) & ~3;
352+
return reinterpret_cast<container::pmr::memory_resource*>(i);
353+
}
354+
return default_resource::get();
354355
}
355356

356357
/** Return a pointer to the memory resource.

0 commit comments

Comments
 (0)