From 44adba28455e0e873480884b292fbe1d4b7763a5 Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Mon, 5 Apr 2021 22:52:36 +0200 Subject: Rename and fixed clist_X_splice_out(L, begin, end) to clist_X_split(L, begin, end). --- docs/clist_api.md | 4 ++-- stc/clist.h | 20 +++++++++++--------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/docs/clist_api.md b/docs/clist_api.md index 49656ea5..857e49a2 100644 --- a/docs/clist_api.md +++ b/docs/clist_api.md @@ -74,8 +74,8 @@ size_t clist_X_remove(clist_X* self, RawValue raw); void clist_X_splice(clist_X* self, clist_X_iter_t it, clist_X* other); void clist_X_splice_range(clist_X* self, clist_X_iter_t it, clist_X* other, clist_X_iter_t it1, clist_X_iter_t it2); - // non-std: splice out [it1, it2) of self, returned as a clist -clist_X clist_X_splice_out(clist_X* self, clist_X_iter_t it1, clist_X_iter_t it2); + // non-std: split out [it1, it2) from self, returned as a clist +clist_X clist_X_split(clist_X* self, clist_X_iter_t it1, clist_X_iter_t it2); clist_X_iter_t clist_X_find(const clist_X* self, RawValue raw); clist_X_iter_t clist_X_find_in_range(const clist_X* self, diff --git a/stc/clist.h b/stc/clist.h index 2c6ada5a..31d6ec88 100644 --- a/stc/clist.h +++ b/stc/clist.h @@ -168,12 +168,12 @@ STC_API size_t _clist_size(const clist_void* self); STC_API void \ clist_##X##_splice(clist_##X* self, clist_##X##_iter_t pos, clist_##X* other); \ STC_API clist_##X \ - clist_##X##_splice_out(clist_##X* self, clist_##X##_iter_t pos1, clist_##X##_iter_t pos2); \ + clist_##X##_split(clist_##X* self, clist_##X##_iter_t pos1, clist_##X##_iter_t pos2); \ \ STC_INLINE void \ clist_##X##_splice_range(clist_##X* self, clist_##X##_iter_t pos, \ clist_##X* other, clist_##X##_iter_t pos1, clist_##X##_iter_t pos2) { \ - clist_##X tmp = clist_##X##_splice_out(other, pos1, pos2); \ + clist_##X tmp = clist_##X##_split(other, pos1, pos2); \ clist_##X##_splice(self, pos, &tmp); \ } \ \ @@ -304,13 +304,15 @@ STC_API size_t _clist_size(const clist_void* self); } \ \ STC_DEF clist_##X \ - clist_##X##_splice_out(clist_##X* self, clist_##X##_iter_t pos1, clist_##X##_iter_t pos2) { \ - clist_##X##_node_t *p1 = pos1._prev, *next1 = _clist_node(X, pos1.ref), \ - *p2 = pos2._prev ? pos2._prev : self->last; \ - clist_##X list = {p2}; \ - if (!(p1 && p2)) return list; \ - p1->next = p2->next, p2->next = next1; \ - if (self->last == p2) self->last = p1; \ + clist_##X##_split(clist_##X* self, clist_##X##_iter_t pos1, clist_##X##_iter_t pos2) { \ + clist_##X##_node_t *p1 = pos1.ref ? pos1._prev : NULL, \ + *p2 = pos2.ref ? pos2._prev : self->last; \ + clist_##X list = {NULL}; \ + if (p1 && p2) { \ + p1->next = p2->next, p2->next = _clist_node(X, pos1.ref); \ + if (self->last == p2) self->last = pos2.ref ? p1 : NULL; \ + list.last = p2; \ + } \ return list; \ } \ \ -- cgit v1.2.3