xo-object2: + DArray gc hooks for AGCObject
This commit is contained in:
parent
eae117a5d3
commit
f5b071f103
2 changed files with 46 additions and 1 deletions
|
|
@ -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*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue