From 9b614f4ff226da918d9f730a7531f40d2e333aab Mon Sep 17 00:00:00 2001 From: Wilmer Paulino Date: Mon, 17 Jul 2023 10:45:39 -0700 Subject: [PATCH] Drop use of RefCell in DebugIter The `RefCell` was necessary in a previous iteration of the code in which the iterator was not `Clone` so we needed interior mutability in order to consume the iterator. Now that it is `Clone`, we can drop it, as we're no longer mutating the original iterator. --- lightning/src/util/logger.rs | 11 ++++------- lightning/src/util/macro_logger.rs | 2 +- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/lightning/src/util/logger.rs b/lightning/src/util/logger.rs index 722a81f7a..dbca9b785 100644 --- a/lightning/src/util/logger.rs +++ b/lightning/src/util/logger.rs @@ -173,18 +173,15 @@ impl<'a> core::fmt::Display for DebugBytes<'a> { /// /// This is not exported to bindings users as fmt can't be used in C #[doc(hidden)] -pub struct DebugIter + Clone>(pub core::cell::RefCell); +pub struct DebugIter + Clone>(pub I); impl + Clone> fmt::Display for DebugIter { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { - use core::ops::DerefMut; write!(f, "[")?; - let iter_ref = self.0.clone(); - let mut iter = iter_ref.borrow_mut(); - for item in iter.deref_mut() { + let mut iter = self.0.clone(); + if let Some(item) = iter.next() { write!(f, "{}", item)?; - break; } - for item in iter.deref_mut() { + while let Some(item) = iter.next() { write!(f, ", {}", item)?; } write!(f, "]")?; diff --git a/lightning/src/util/macro_logger.rs b/lightning/src/util/macro_logger.rs index 4703bcdb3..e79980370 100644 --- a/lightning/src/util/macro_logger.rs +++ b/lightning/src/util/macro_logger.rs @@ -19,7 +19,7 @@ use crate::util::logger::DebugBytes; macro_rules! log_iter { ($obj: expr) => { - $crate::util::logger::DebugIter(core::cell::RefCell::new($obj)) + $crate::util::logger::DebugIter($obj) } } -- 2.39.5