Skip to content

Commit 5481e25

Browse files
committed
FIX: Factor out duplicate code in Zip::and and Zip::and_broadcast
Since these methods are duplicated fivefold, it might actually be a good saving, even if it's a small method. And we don't have to write the layout combination code twice.
1 parent 85e1813 commit 5481e25

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/zip/mod.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -969,15 +969,9 @@ macro_rules! map_impl {
969969
pub fn and<P>(self, p: P) -> Zip<($($p,)* P::Output, ), D>
970970
where P: IntoNdProducer<Dim=D>,
971971
{
972-
let array = p.into_producer();
973-
self.check(&array);
974-
let part_layout = array.layout();
975-
let ($($p,)*) = self.parts;
976-
Zip {
977-
parts: ($($p,)* array, ),
978-
layout: self.layout.and(part_layout),
979-
dimension: self.dimension,
980-
}
972+
let part = p.into_producer();
973+
self.check(&part);
974+
self.build_and(part)
981975
}
982976

983977
/// Include the producer `p` in the Zip, broadcasting if needed.
@@ -990,11 +984,17 @@ macro_rules! map_impl {
990984
where P: IntoNdProducer<Dim=D2, Output=ArrayView<'a, Elem, D2>, Item=&'a Elem>,
991985
D2: Dimension,
992986
{
993-
let array = p.into_producer().broadcast_unwrap(self.dimension.clone());
994-
let part_layout = array.layout();
987+
let part = p.into_producer().broadcast_unwrap(self.dimension.clone());
988+
self.build_and(part)
989+
}
990+
991+
fn build_and<P>(self, part: P) -> Zip<($($p,)* P, ), D>
992+
where P: NdProducer<Dim=D>,
993+
{
994+
let part_layout = part.layout();
995995
let ($($p,)*) = self.parts;
996996
Zip {
997-
parts: ($($p,)* array, ),
997+
parts: ($($p,)* part, ),
998998
layout: self.layout.and(part_layout),
999999
dimension: self.dimension,
10001000
}

0 commit comments

Comments
 (0)