From c6fbaf7b5ef850a1a92dd0e43c0e75cc6db792c6 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Sun, 21 Dec 2025 16:20:13 -0500 Subject: [PATCH] xo-alloc2: working operator* for AAllocIterator --- include/xo/alloc2/alloc/RAllocIterator.hpp | 2 ++ src/alloc2/IAllocIterator_DArenaIterator.cpp | 2 +- .../IAllocIterator_DX1CollectorIterator.cpp | 2 +- utest/DArenaIterator.test.cpp | 16 ++++++++++++++++ utest/DX1CollectorIterator.test.cpp | 16 ++++++++++++++++ 5 files changed, 36 insertions(+), 2 deletions(-) diff --git a/include/xo/alloc2/alloc/RAllocIterator.hpp b/include/xo/alloc2/alloc/RAllocIterator.hpp index 6a14218..73602cc 100644 --- a/include/xo/alloc2/alloc/RAllocIterator.hpp +++ b/include/xo/alloc2/alloc/RAllocIterator.hpp @@ -27,6 +27,8 @@ namespace xo { return O::iface()->compare(O::data(), other); } void next() noexcept { O::iface()->next(O::data()); } + AllocInfo operator*() const noexcept { return deref(); } + /** triggers operator++ in obj> **/ void _preincrement() noexcept { this->next(); } diff --git a/src/alloc2/IAllocIterator_DArenaIterator.cpp b/src/alloc2/IAllocIterator_DArenaIterator.cpp index cfb9a34..dc0e1bc 100644 --- a/src/alloc2/IAllocIterator_DArenaIterator.cpp +++ b/src/alloc2/IAllocIterator_DArenaIterator.cpp @@ -32,7 +32,7 @@ namespace xo { if (!other) return cmpresult::incomparable(); - DArenaIterator & other_ix = *other; + DArenaIterator & other_ix = *other.data(); log && log(xtag("&other_ix", &other_ix), xtag("other_ix.arena", other_ix.arena_), diff --git a/src/alloc2/IAllocIterator_DX1CollectorIterator.cpp b/src/alloc2/IAllocIterator_DX1CollectorIterator.cpp index 2cb22e3..85609f1 100644 --- a/src/alloc2/IAllocIterator_DX1CollectorIterator.cpp +++ b/src/alloc2/IAllocIterator_DX1CollectorIterator.cpp @@ -25,7 +25,7 @@ namespace xo { if (!other) return cmpresult::incomparable(); - DX1CollectorIterator & other_ix = *other; + DX1CollectorIterator & other_ix = *other.data(); return ix.compare(other_ix); } diff --git a/utest/DArenaIterator.test.cpp b/utest/DArenaIterator.test.cpp index a42fc46..a585071 100644 --- a/utest/DArenaIterator.test.cpp +++ b/utest/DArenaIterator.test.cpp @@ -269,6 +269,22 @@ namespace xo { REQUIRE(ix == end_ix); } } + + // repeat, this time using range iteration + { + DArena scratch_mm + = DArena::map( + ArenaConfig{ + .size_ = 4*1024, + .hugepage_z_ = 4*1024}); + + for (const auto & info : a1o.alloc_range(scratch_mm)) { + REQUIRE(info.is_valid()); + REQUIRE(info.size() == padding::with_padding(req_z)); + REQUIRE(info.payload().first == mem); + REQUIRE(info.payload().second == mem + info.size()); + } + } } } /*namespace ut*/ diff --git a/utest/DX1CollectorIterator.test.cpp b/utest/DX1CollectorIterator.test.cpp index 941d1d0..3ae405e 100644 --- a/utest/DX1CollectorIterator.test.cpp +++ b/utest/DX1CollectorIterator.test.cpp @@ -198,6 +198,22 @@ namespace xo { REQUIRE(ix == end_ix); } } + + // repeat, this time using range iteration + { + DArena scratch_mm + = DArena::map( + ArenaConfig{ + .size_ = 4*1024, + .hugepage_z_ = 4*1024}); + + for (const auto & info : a1o.alloc_range(scratch_mm)) { + REQUIRE(info.is_valid()); + REQUIRE(info.size() == padding::with_padding(req_z)); + REQUIRE(info.payload().first == mem); + REQUIRE(info.payload().second == mem + info.size()); + } + } } } /*namespace ut*/ } /*namespace xo*/