From 793c24ce9ebbb112e93f7b4362a562a8dbf0e780 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Thu, 19 Apr 2018 14:47:56 -0700 Subject: [PATCH] ircd::ctx: Simplify list iteration API. --- include/ircd/ctx/list.h | 12 ++++------- ircd/ctx.cc | 46 ++++++++++++++++++++--------------------- 2 files changed, 27 insertions(+), 31 deletions(-) diff --git a/include/ircd/ctx/list.h b/include/ircd/ctx/list.h index 4675dd323..0eaf01927 100644 --- a/include/ircd/ctx/list.h +++ b/include/ircd/ctx/list.h @@ -45,19 +45,15 @@ class ircd::ctx::list ctx *front(); ctx *back(); - // until convention - bool until(const std::function &) const; - bool until(const std::function &); - - // reverse until convention - bool runtil(const std::function &) const; - bool runtil(const std::function &); - // iteration + bool for_each(const std::function &) const; + bool for_each(const std::function &); void for_each(const std::function &) const; void for_each(const std::function &); // reverse iteration + bool rfor_each(const std::function &) const; + bool rfor_each(const std::function &); void rfor_each(const std::function &) const; void rfor_each(const std::function &); diff --git a/ircd/ctx.cc b/ircd/ctx.cc index 4d2b76507..a83676f39 100644 --- a/ircd/ctx.cc +++ b/ircd/ctx.cc @@ -1311,6 +1311,27 @@ const closure(*tail); } +bool +ircd::ctx::list::rfor_each(const std::function &closure) +{ + for(ctx *tail{this->tail}; tail; tail = prev(tail)) + if(!closure(*tail)) + return false; + + return true; +} + +bool +ircd::ctx::list::rfor_each(const std::function &closure) +const +{ + for(const ctx *tail{this->tail}; tail; tail = prev(tail)) + if(!closure(*tail)) + return false; + + return true; +} + void ircd::ctx::list::for_each(const std::function &closure) { @@ -1327,28 +1348,7 @@ const } bool -ircd::ctx::list::runtil(const std::function &closure) -{ - for(ctx *tail{this->tail}; tail; tail = prev(tail)) - if(!closure(*tail)) - return false; - - return true; -} - -bool -ircd::ctx::list::runtil(const std::function &closure) -const -{ - for(const ctx *tail{this->tail}; tail; tail = prev(tail)) - if(!closure(*tail)) - return false; - - return true; -} - -bool -ircd::ctx::list::until(const std::function &closure) +ircd::ctx::list::for_each(const std::function &closure) { for(ctx *head{this->head}; head; head = next(head)) if(!closure(*head)) @@ -1358,7 +1358,7 @@ ircd::ctx::list::until(const std::function &closure) } bool -ircd::ctx::list::until(const std::function &closure) +ircd::ctx::list::for_each(const std::function &closure) const { for(const ctx *head{this->head}; head; head = next(head))