From 8f1361763e50b8e1cf0e6096c3d60c0e97b5cb68 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Sun, 11 Jan 2026 12:32:02 -0500 Subject: [PATCH] xo-object2: streamline DList::list use --- include/xo/object2/DList.hpp | 30 ++++++++++++++++++++++++++++++ src/object2/DList.cpp | 2 ++ utest/X1Collector.test.cpp | 5 +++-- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/include/xo/object2/DList.hpp b/include/xo/object2/DList.hpp index 1e863a6..b023f0d 100644 --- a/include/xo/object2/DList.hpp +++ b/include/xo/object2/DList.hpp @@ -34,6 +34,17 @@ namespace xo { obj car, obj cdr); + /** list with one element @p e1, allocated from @p mm **/ + template + static obj list(obj mm, + obj e1); + + /** list with two element @p e1, @p e2, allocated from @p mm **/ + template + static obj list(obj mm, + obj e1, + obj e2); + /** sentinel for null list **/ static DList * _nil(); @@ -45,6 +56,7 @@ namespace xo { obj car, DList * cdr); +#ifdef OBSOLETE /** list with one element @p h1, allocated from @p mm **/ static DList * list(obj mm, obj h1); @@ -52,6 +64,7 @@ namespace xo { static DList * list(obj mm, obj h1, obj h2); +#endif /** DList length is at least 1 **/ bool is_empty() const noexcept; @@ -87,6 +100,23 @@ namespace xo { return obj(DList::_cons(mm, car, cdr.data())); } + template + obj + DList::list(obj mm, + obj e1) + { + return cons(mm, e1, nil()); + } + + template + obj + DList::list(obj mm, + obj e1, + obj e2) + { + return cons(mm, e1, list(mm, e2)); + } + } /*namespace scm*/ } /*namespace xo*/ diff --git a/src/object2/DList.cpp b/src/object2/DList.cpp index 777d503..934fa50 100644 --- a/src/object2/DList.cpp +++ b/src/object2/DList.cpp @@ -34,6 +34,7 @@ namespace xo { return new (mem) DList(car, cdr); } +#ifdef OBSOLETE DList * DList::list(obj mm, obj h1) @@ -52,6 +53,7 @@ namespace xo { return new (mem) DList(h1, DList::list(mm, h2)); } +#endif bool DList::is_empty() const noexcept diff --git a/utest/X1Collector.test.cpp b/utest/X1Collector.test.cpp index cec744e..1536ebf 100644 --- a/utest/X1Collector.test.cpp +++ b/utest/X1Collector.test.cpp @@ -171,8 +171,9 @@ namespace ut { c_o.add_gc_root(&x0_o); REQUIRE(to_0->allocated() == sizeof(AllocHeader) + sizeof(DFloat)); - DList * l0 = DList::list(gc_o, x0_o); - auto l0_o = with_facet::mkobj(l0); + //DList * l0 = DList::list(gc_o, x0_o); + //auto l0_o = with_facet::mkobj(l0); + auto l0_o = DList::list(gc_o, x0_o); c_o.add_gc_root(&l0_o); REQUIRE(to_0->allocated() == (sizeof(AllocHeader) + sizeof(DFloat) + sizeof(AllocHeader) + sizeof(DList)));