From cf04d4d852087b4915c3c5c28c8290c9945050c2 Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Fri, 6 Dec 2024 20:47:47 +0100 Subject: [PATCH] refactor(tasks): simplify up_to back --- src/tasks.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/tasks.rs b/src/tasks.rs index 66b2b05..81ea4cc 100644 --- a/src/tasks.rs +++ b/src/tasks.rs @@ -402,8 +402,11 @@ impl TasksRelay { /// Move up `count` parent tasks from current position pub(crate) fn up_by(&self, count: usize) -> Option { let pos = self.get_position(); - if count < 1 { return pos; } - self.traverse_up_from(pos).nth(count - 1)?.parent_id().cloned() + let mut result = pos.as_ref(); + for _ in 0..count { + result = self.get_parent(result); + } + result.cloned() } pub(crate) fn get_parent(&self, id: Option<&EventId>) -> Option<&EventId> {