From bf2218260ec3934efb13f953c5a8141c6978be0a Mon Sep 17 00:00:00 2001 From: Arik Sosman Date: Thu, 22 Jun 2023 14:14:02 -0700 Subject: [PATCH] Reference-rhs bitwise operations for features. --- lightning/src/ln/features.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lightning/src/ln/features.rs b/lightning/src/ln/features.rs index 400888ff9..3e3484e73 100644 --- a/lightning/src/ln/features.rs +++ b/lightning/src/ln/features.rs @@ -77,6 +77,7 @@ use crate::{io, io_extras}; use crate::prelude::*; use core::{cmp, fmt}; +use core::borrow::Borrow; use core::hash::{Hash, Hasher}; use core::marker::PhantomData; @@ -431,15 +432,21 @@ pub struct Features { mark: PhantomData, } +impl> core::ops::BitOrAssign for Features { + fn bitor_assign(&mut self, rhs: Rhs) { + let total_feature_len = cmp::max(self.flags.len(), rhs.borrow().flags.len()); + self.flags.resize(total_feature_len, 0u8); + for (byte, rhs_byte) in self.flags.iter_mut().zip(rhs.borrow().flags.iter()) { + *byte |= *rhs_byte; + } + } +} + impl core::ops::BitOr for Features { type Output = Self; fn bitor(mut self, o: Self) -> Self { - let total_feature_len = cmp::max(self.flags.len(), o.flags.len()); - self.flags.resize(total_feature_len, 0u8); - for (byte, o_byte) in self.flags.iter_mut().zip(o.flags.iter()) { - *byte |= *o_byte; - } + self |= o; self } } -- 2.39.5