mirror of https://github.com/CGAL/cgal
simpler timestamp system
This commit is contained in:
parent
ec1d97bea9
commit
33c3d22bf8
|
|
@ -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<allocator_type>::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<std::ptrdiff_t>(p) -
|
||||
reinterpret_cast<std::ptrdiff_t>(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<std::size_t>(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);
|
||||
|
|
|
|||
|
|
@ -29,27 +29,18 @@ template <typename T>
|
|||
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 <typename time_stamp_t>
|
||||
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.
|
||||
|
|
|
|||
Loading…
Reference in New Issue