all: minor updates

This commit is contained in:
Markus F.X.J. Oberhumer
2024-02-04 13:37:00 +01:00
parent 41f6945be1
commit 29ce4807fb
6 changed files with 27 additions and 12 deletions
+4
View File
@@ -253,6 +253,10 @@ TEST_CASE("MemBuffer core") {
CHECK_THROWS(mb.alloc(0x30000000 + 1));
CHECK(raw_bytes(mb, 0) == nullptr);
CHECK_THROWS(raw_bytes(mb, 1));
CHECK_THROWS(mb.begin());
CHECK_THROWS(mb.end());
CHECK_THROWS(mb.cbegin());
CHECK_THROWS(mb.cend());
mb.alloc(N);
mb.checkState();
CHECK(mb.begin() == mb.cbegin());
+1 -2
View File
@@ -45,8 +45,7 @@ public:
typedef pointer iterator;
typedef typename std::add_pointer<const T>::type const_iterator;
protected:
static constexpr size_t element_size = sizeof(element_type);
static_assert(element_size >= 1 && element_size <= UPX_RSIZE_MAX_MEM);
static const size_t element_size = sizeof(element_type);
protected:
pointer ptr;
+12 -9
View File
@@ -271,14 +271,17 @@ public:
Self &operator=(MemBuffer &mb) { return assign(Self(mb)); }
#endif
// subspan (creates a new value)
Self subspan(ptrdiff_t offset, ptrdiff_t count) const {
pointer begin = check_add(ptr, offset);
pointer end = check_add(begin, count);
if (begin <= end)
return Self(Unchecked, begin, (end - begin) * sizeof(T), begin);
pointer p_begin = check_add(ptr, offset);
pointer p_end = check_add(p_begin, count);
if (p_begin <= p_end)
return Self(Unchecked, p_begin, (p_end - p_begin) * sizeof(T), p_begin);
else
return Self(Unchecked, end, (begin - end) * sizeof(T), end);
return Self(Unchecked, p_end, (p_begin - p_end) * sizeof(T), p_end);
}
// subspan (creates a new value)
Self subspan(ptrdiff_t offset) const { return subspan(offset, size() - offset); }
// cast to a different type (creates a new value)
template <class U>
@@ -454,16 +457,16 @@ public: // raw access
// like C++20 std::span
pointer data() const noexcept { return ptr; }
pointer data(size_t bytes) const { return raw_bytes(bytes); } // UPX extra
// size_type size() const { return size_bytes() / sizeof(element_type); } // NOT USED
size_type size() const noexcept { return size_bytes() / sizeof(element_type); }
size_type size_bytes() const {
assertInvariants();
if __acc_cte (!configRequirePtr && ptr == nullptr)
return 0;
if __acc_cte (!configRequireBase && base == nullptr)
return 0;
const charptr begin = (const charptr) ptr;
const charptr end = (const charptr) base + size_in_bytes;
return end - begin;
const charptr p_begin = (const charptr) ptr;
const charptr p_end = (const charptr) base + size_in_bytes;
return p_end - p_begin;
}
#if CLANG_FORMAT_DUMMY_CLASS