From 33c3d22bf8516bd504af9ecde5333ab4df34e349 Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Thu, 22 Feb 2024 13:40:58 +0100 Subject: [PATCH] simpler timestamp system --- STL_Extension/include/CGAL/Compact_container.h | 16 ++++++++-------- STL_Extension/include/CGAL/Time_stamper.h | 11 +---------- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/STL_Extension/include/CGAL/Compact_container.h b/STL_Extension/include/CGAL/Compact_container.h index e82a33412d9..6778f94e041 100644 --- a/STL_Extension/include/CGAL/Compact_container.h +++ b/STL_Extension/include/CGAL/Compact_container.h @@ -403,10 +403,17 @@ public: pointer ret = free_list; free_list = clean_pointee(ret); + std::size_t ts; + if constexpr (Time_stamper::has_timestamp) { + ts = ret->time_stamp(); + } std::allocator_traits::construct(alloc, ret, t); + if constexpr (Time_stamper::has_timestamp) { + ret->set_time_stamp(ts); + } + Time_stamper::set_time_stamp(ret, time_stamp); CGAL_assertion(type(ret) == USED); ++size_; - Time_stamper::set_time_stamp(ret, time_stamp); return iterator(ret, 0); } @@ -652,9 +659,6 @@ private: // Get the type of the pointee. static Type type(const_pointer ptr) { - if constexpr (Time_stamper::has_timestamp) { - return (Type)(ptr->time_stamp() >> Time_stamper::time_stamp_shift); - } char * p = (char *) Traits::pointer(*ptr); return (Type) (reinterpret_cast(p) - reinterpret_cast(clean_pointer(p))); @@ -663,10 +667,6 @@ private: // Sets the pointer part and the type of the pointee. static void set_type(pointer ptr, void * p, Type t) { - if constexpr (Time_stamper::has_timestamp) { - const auto ts = ptr->time_stamp() & ~(Time_stamper::time_stamp_mask); - ptr->set_time_stamp(ts | (static_cast(t) << Time_stamper::time_stamp_shift)); - } // This out of range compare is always true and causes lots of // unnecessary warnings. // CGAL_precondition(0 <= t && t < 4); diff --git a/STL_Extension/include/CGAL/Time_stamper.h b/STL_Extension/include/CGAL/Time_stamper.h index 7afe7160eee..645900760eb 100644 --- a/STL_Extension/include/CGAL/Time_stamper.h +++ b/STL_Extension/include/CGAL/Time_stamper.h @@ -29,27 +29,18 @@ template struct Time_stamper { static constexpr bool has_timestamp = true; - static constexpr int time_stamp_shift = sizeof(std::size_t) * CHAR_BIT - 2; - static constexpr std::size_t time_stamp_mask = std::size_t(0b11) << time_stamp_shift; - static constexpr std::size_t time_stamp_is_free_mask = std::size_t(0b001) << (time_stamp_shift - 1); static void initialize_time_stamp(T* pt) { pt->set_time_stamp(std::size_t(-1)); } - static bool is_free(const T* pt) - { - return ( pt->time_stamp() & time_stamp_is_free_mask )!= 0; - } - template static void set_time_stamp(T* pt, time_stamp_t& time_stamp_) { - if(is_free(pt)) { + if(pt->time_stamp() == std::size_t(-1)) { const std::size_t new_ts = time_stamp_++; pt->set_time_stamp(new_ts); } else { - pt->set_time_stamp(pt->time_stamp() & ~time_stamp_mask); // else: the time stamp is re-used // Enforces that the time stamp is greater than the current value.