From 6bee0f8a9be892e05863a6f13dfb405489fb6b0c Mon Sep 17 00:00:00 2001 From: Roman Proskuryakov Date: Sat, 3 Apr 2021 22:20:09 +0300 Subject: [PATCH] Simplify code in histbuf --- src/histbuf.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/histbuf.rs b/src/histbuf.rs index 4fed656562..01cb000291 100644 --- a/src/histbuf.rs +++ b/src/histbuf.rs @@ -174,11 +174,7 @@ impl HistoryBuffer { /// Returns the array slice backing the buffer, without keeping track /// of the write position. Therefore, the element order is unspecified. pub fn as_slice(&self) -> &[T] { - if self.filled { - unsafe { slice::from_raw_parts(self.data.as_ptr() as *const _, self.capacity()) } - } else { - unsafe { slice::from_raw_parts(self.data.as_ptr() as *const _, self.write_at) } - } + unsafe { slice::from_raw_parts(self.data.as_ptr() as *const _, self.len()) } } } @@ -276,6 +272,8 @@ mod tests { fn as_slice() { let mut x: HistoryBuffer = HistoryBuffer::new(); + assert_eq!(x.as_slice(), []); + x.extend([1, 2, 3, 4, 5].iter()); assert_eq!(x.as_slice(), [5, 2, 3, 4]);