Skip to content

Commit 3554509

Browse files
author
Gilad Chase
committed
refactor(byte_array): delegate ByteArray iterator into ByteSpan iterator
Faster than current approach, which uses `at`.
1 parent 727b961 commit 3554509

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

corelib/src/byte_array.cairo

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -706,26 +706,25 @@ pub(crate) impl ByteArrayIndexView of crate::traits::IndexView<ByteArray, usize,
706706
}
707707
}
708708

709-
// TODO(giladchase): Delegate to byte span iterator instead of current at-based implementation.
710709
/// An iterator struct over a ByteArray.
711710
#[derive(Drop, Clone)]
712711
pub struct ByteArrayIter {
713-
ba: ByteArray,
714-
current_index: IntoIterator::<crate::ops::Range<usize>>::IntoIter,
712+
inner: ByteSpanIter,
715713
}
716714

717715
impl ByteArrayIterator of crate::iter::Iterator<ByteArrayIter> {
718716
type Item = u8;
717+
#[inline]
719718
fn next(ref self: ByteArrayIter) -> Option<u8> {
720-
self.ba.at(self.current_index.next()?)
719+
self.inner.next()
721720
}
722721
}
723722

724723
impl ByteArrayIntoIterator of crate::iter::IntoIterator<ByteArray> {
725724
type IntoIter = ByteArrayIter;
726725
#[inline]
727726
fn into_iter(self: ByteArray) -> Self::IntoIter {
728-
ByteArrayIter { current_index: (0..self.len()).into_iter(), ba: self }
727+
ByteArrayIter { inner: self.span().into_iter() }
729728
}
730729
}
731730

0 commit comments

Comments
 (0)