diff options
author | Wilfred Hughes <me@wilfred.me.uk> | 2023-08-04 08:35:05 -0700 |
---|---|---|
committer | Wilfred Hughes <me@wilfred.me.uk> | 2023-08-16 10:43:10 -0700 |
commit | 4aa0f870cc5bbd07b8b13fee3034ff717611cb82 (patch) | |
tree | a8898463502f46af765a3ee91dd9158f7c963f85 | |
parent | 31e3d1f75055480e4e7097a2ddf510e5bd1a4e12 (diff) |
Implement PartialEq directly
-rw-r--r-- | src/diff/stack.rs | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/src/diff/stack.rs b/src/diff/stack.rs index 1fc8ff867..30761ff61 100644 --- a/src/diff/stack.rs +++ b/src/diff/stack.rs @@ -2,19 +2,43 @@ use std::rc::Rc; use bumpalo::Bump; -#[derive(Debug, Clone, Default, PartialEq, Eq)] +/// A bump allocated, persistent stack. +#[derive(Debug, Clone, Default, PartialEq)] pub struct BumpStack<'b, T> { head: Option<&'b BumpStackNode<'b, T>>, } // TODO: equality checks on this are super hot (11% runtime for // slow_before.rs), see if storing length helps. -#[derive(Debug, Clone, Default, PartialEq, Eq)] +#[derive(Debug, Clone, Default)] struct BumpStackNode<'b, T> { value: T, next: Option<&'b BumpStackNode<'b, T>>, } +impl<'b, T> PartialEq for BumpStackNode<'b, T> +where + T: PartialEq, +{ + fn eq(&self, other: &Self) -> bool { + if self.value != other.value { + return false; + } + + match (self.next, other.next) { + (Some(self_next), Some(other_next)) => { + if std::ptr::eq(self_next, other_next) { + return true; + } + + self_next == other_next + } + (None, None) => true, + _ => false, + } + } +} + impl<'b, T> BumpStack<'b, T> { pub(crate) fn new() -> Self { Self { head: None } @@ -57,4 +81,3 @@ struct Node<T> { val: T, next: Option<Rc<Node<T>>>, } - |