refactor: use GCObjectVisitor api w/ gco_shallow_move

This commit is contained in:
Roland Conybeare 2026-04-06 15:21:48 -04:00
commit 7d3d2d7070
8 changed files with 16 additions and 22 deletions

View file

@ -6,7 +6,7 @@
#pragma once
#include <xo/alloc2/Allocator.hpp>
#include <xo/alloc2/Collector.hpp>
//#include <xo/alloc2/Collector.hpp>
#include <xo/alloc2/GCObjectVisitor.hpp>
#include <xo/facet/obj.hpp>
#include <xo/indentlog/print/ppindentinfo.hpp>
@ -47,7 +47,7 @@ namespace xo {
/** xo allocator **/
using AAllocator = xo::mm::AAllocator;
/** garbage collector **/
using ACollector = xo::mm::ACollector;
//using ACollector = xo::mm::ACollector;
/** object visitor (garbage collector proxy) **/
using AGCObjectVisitor = xo::mm::AGCObjectVisitor;
/** ppindentinfo for APrintable **/
@ -245,10 +245,8 @@ namespace xo {
/** @defgroup dstring-gcobject-methods gcobject facet methods **/
///@{
size_type shallow_size() const noexcept;
/** clone string, using memory from allocator @p mm **/
DString * shallow_move(obj<ACollector> gc) noexcept;
DString * gco_shallow_move(obj<AGCObjectVisitor> gc) noexcept;
/** fixup child pointers (trivial for DString, no children)
* note: cref so we can use forward decl

View file

@ -90,7 +90,7 @@ namespace xo {
///@{
/** clone unique string, using memory from allocator @p mm. **/
DUniqueString * shallow_move(obj<ACollector> gc) noexcept;
DUniqueString * gco_shallow_move(obj<AGCObjectVisitor> gc) noexcept;
/** fixup child pointers (trivial for DUniqueString, no gc-owned children **/
void visit_gco_children(obj<AGCObjectVisitor> gc) noexcept;

View file

@ -53,8 +53,9 @@ namespace xo {
// const methods
// non-const methods
/** move instance using collector **/
static Opaque shallow_move(DString & self, obj<ACollector> gc) noexcept;
/** move instance using object visitor.
Arguably abusing the word 'visitor' here **/
static Opaque gco_shallow_move(DString & self, obj<AGCObjectVisitor> gc) noexcept;
/** Invoke fn.visit_child(iface,data) for each child GCObject pointer.
Context: provides address of data pointer so it can be updated in place
when @p fn invokes garbage collector reentry point **/

View file

@ -53,8 +53,9 @@ namespace xo {
// const methods
// non-const methods
/** move instance using collector **/
static Opaque shallow_move(DUniqueString & self, obj<ACollector> gc) noexcept;
/** move instance using object visitor.
Arguably abusing the word 'visitor' here **/
static Opaque gco_shallow_move(DUniqueString & self, obj<AGCObjectVisitor> gc) noexcept;
/** Invoke fn.visit_child(iface,data) for each child GCObject pointer.
Context: provides address of data pointer so it can be updated in place
when @p fn invokes garbage collector reentry point **/

View file

@ -149,14 +149,8 @@ namespace xo {
return this->size_;
}
auto
DString::shallow_size() const noexcept -> size_type
{
return sizeof(DString) + capacity_;
}
DString *
DString::shallow_move(obj<ACollector> gc) noexcept
DString::gco_shallow_move(obj<AGCObjectVisitor> gc) noexcept
{
// note: not using gc.std_move_for() here
// b/c DString flexible array means not move-constructible

View file

@ -82,7 +82,7 @@ namespace xo {
}
DUniqueString *
DUniqueString::shallow_move(obj<ACollector> gc) noexcept
DUniqueString::gco_shallow_move(obj<AGCObjectVisitor> gc) noexcept
{
// well-posed, but not expected to be used.
//

View file

@ -16,9 +16,9 @@
namespace xo {
namespace scm {
auto
IGCObject_DString::shallow_move(DString & self, obj<ACollector> gc) noexcept -> Opaque
IGCObject_DString::gco_shallow_move(DString & self, obj<AGCObjectVisitor> gc) noexcept -> Opaque
{
return self.shallow_move(gc);
return self.gco_shallow_move(gc);
}
auto
IGCObject_DString::visit_gco_children(DString & self, obj<AGCObjectVisitor> fn) noexcept -> void

View file

@ -16,9 +16,9 @@
namespace xo {
namespace scm {
auto
IGCObject_DUniqueString::shallow_move(DUniqueString & self, obj<ACollector> gc) noexcept -> Opaque
IGCObject_DUniqueString::gco_shallow_move(DUniqueString & self, obj<AGCObjectVisitor> gc) noexcept -> Opaque
{
return self.shallow_move(gc);
return self.gco_shallow_move(gc);
}
auto
IGCObject_DUniqueString::visit_gco_children(DUniqueString & self, obj<AGCObjectVisitor> fn) noexcept -> void