From d718bc292d342a99580ec971dc7e873e5fc6e5c4 Mon Sep 17 00:00:00 2001 From: Michael Arntzenius Date: Wed, 28 Nov 2012 12:35:08 -0500 Subject: [PATCH 1/3] libcore/to_bytes.rs: add IterBytes impls for pairs and triples --- src/libcore/to_bytes.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/libcore/to_bytes.rs b/src/libcore/to_bytes.rs index ef15aa00f11..3aaa3ab8d91 100644 --- a/src/libcore/to_bytes.rs +++ b/src/libcore/to_bytes.rs @@ -191,6 +191,25 @@ impl &[A]: IterBytes { } } +impl (A,B): IterBytes { + #[inline(always)] + pure fn iter_bytes(lsb0: bool, f: Cb) { + let &(ref a, ref b) = &self; + a.iter_bytes(lsb0, f); + b.iter_bytes(lsb0, f); + } +} + +impl (A,B,C): IterBytes { + #[inline(always)] + pure fn iter_bytes(lsb0: bool, f: Cb) { + let &(ref a, ref b, ref c) = &self; + a.iter_bytes(lsb0, f); + b.iter_bytes(lsb0, f); + c.iter_bytes(lsb0, f); + } +} + // Move this to vec, probably. pure fn borrow(a: &x/[A]) -> &x/[A] { a From ef2c404e01108a7bd7465bd23d40ff989848bffd Mon Sep 17 00:00:00 2001 From: Michael Arntzenius Date: Wed, 28 Nov 2012 22:55:51 -0500 Subject: [PATCH 2/3] libcore/to_bytes.rs: fix IterBytes instances for pairs, triples to not cause ICE when used --- src/libcore/to_bytes.rs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/libcore/to_bytes.rs b/src/libcore/to_bytes.rs index 3aaa3ab8d91..238b4342a63 100644 --- a/src/libcore/to_bytes.rs +++ b/src/libcore/to_bytes.rs @@ -194,19 +194,25 @@ impl &[A]: IterBytes { impl (A,B): IterBytes { #[inline(always)] pure fn iter_bytes(lsb0: bool, f: Cb) { - let &(ref a, ref b) = &self; - a.iter_bytes(lsb0, f); - b.iter_bytes(lsb0, f); + match self { + (ref a, ref b) => { + a.iter_bytes(lsb0, f); + b.iter_bytes(lsb0, f); + } + } } } impl (A,B,C): IterBytes { #[inline(always)] pure fn iter_bytes(lsb0: bool, f: Cb) { - let &(ref a, ref b, ref c) = &self; - a.iter_bytes(lsb0, f); - b.iter_bytes(lsb0, f); - c.iter_bytes(lsb0, f); + match self { + (ref a, ref b, ref c) => { + a.iter_bytes(lsb0, f); + b.iter_bytes(lsb0, f); + c.iter_bytes(lsb0, f); + } + } } } From 5b6c1a2950ba2a8b6377a387f666b0e50c45fc4f Mon Sep 17 00:00:00 2001 From: Michael Arntzenius Date: Sun, 2 Dec 2012 20:01:28 -0500 Subject: [PATCH 3/3] call out to iter_bytes_{2,3} in IterBytes instances for pairs, triples This means we will exit early if requested based on the return value of the callback we're given. --- src/libcore/to_bytes.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/libcore/to_bytes.rs b/src/libcore/to_bytes.rs index 238b4342a63..4ffa24e014e 100644 --- a/src/libcore/to_bytes.rs +++ b/src/libcore/to_bytes.rs @@ -196,8 +196,7 @@ impl (A,B): IterBytes { pure fn iter_bytes(lsb0: bool, f: Cb) { match self { (ref a, ref b) => { - a.iter_bytes(lsb0, f); - b.iter_bytes(lsb0, f); + iter_bytes_2(a, b, lsb0, f); } } } @@ -208,9 +207,7 @@ impl (A,B,C): IterBytes { pure fn iter_bytes(lsb0: bool, f: Cb) { match self { (ref a, ref b, ref c) => { - a.iter_bytes(lsb0, f); - b.iter_bytes(lsb0, f); - c.iter_bytes(lsb0, f); + iter_bytes_3(a, b, c, lsb0, f); } } }