Skip to content

Commit 0a4841e

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

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

corelib/src/byte_array.cairo

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -705,27 +705,24 @@ pub(crate) impl ByteArrayIndexView of crate::traits::IndexView<ByteArray, usize,
705705
}
706706
}
707707

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

716714
impl ByteArrayIterator of crate::iter::Iterator<ByteArrayIter> {
717715
type Item = u8;
718716

719717
fn next(ref self: ByteArrayIter) -> Option<u8> {
720-
self.ba.at(self.current_index.next()?)
718+
self.inner.next()
721719
}
722720
}
723721

724722
impl ByteArrayIntoIterator of crate::iter::IntoIterator<ByteArray> {
725723
type IntoIter = ByteArrayIter;
726-
#[inline]
727724
fn into_iter(self: ByteArray) -> Self::IntoIter {
728-
ByteArrayIter { current_index: (0..self.len()).into_iter(), ba: self }
725+
ByteArrayIter { inner: self.span().into_iter() }
729726
}
730727
}
731728

0 commit comments

Comments
 (0)