xo-object2: + DArray gc hooks for AGCObject

This commit is contained in:
Roland Conybeare 2026-01-15 14:29:09 -05:00
commit f5b071f103
2 changed files with 46 additions and 1 deletions

View file

@ -6,6 +6,7 @@
#include "DArray.hpp"
#include <xo/indentlog/print/tostr.hpp>
#include <xo/indentlog/print/tag.hpp>
#include <cstdint>
namespace xo {
using xo::mm::AGCObject;
@ -64,5 +65,44 @@ namespace xo {
return true;
}
}
// gc hooks for IGCObject_DArray
std::size_t
DArray::shallow_size() const noexcept
{
return sizeof(DArray);
}
DArray *
DArray::shallow_copy(obj<AAllocator> mm) const noexcept
{
DArray * copy = (DArray *)mm.alloc_copy((std::byte *)this);
if (copy) {
copy->capacity_ = capacity_;
copy->size_ = size_;
constexpr auto c_obj_z = sizeof(obj<AGCObject>);
/* memcpy sufficient for obj<A,D> */
::memcpy((void*)&(copy->elts_[0]), (void*)&(elts_[0]), capacity_ * c_obj_z);
}
return copy;
}
std::size_t
DArray::forward_children(obj<ACollector> gc) noexcept
{
for (size_type i = 0; i < size_; ++i) {
obj<AGCObject> & elt = elts_[i];
gc.forward_inplace(elt.iface(), (void **)&(elt.data_));
}
return shallow_size();
}
} /*namespace scm*/
} /*namespace xo*/