about summary refs log tree commit diff
path: root/src/test/codegen
diff options
context:
space:
mode:
authorUlrik Sverdrup <bluss@users.noreply.github.com>2016-10-17 10:58:21 +0200
committerUlrik Sverdrup <bluss@users.noreply.github.com>2016-10-17 10:58:21 +0200
commited5015939f02ce340bf3581c866f7b6ddabb6daf (patch)
tree476af78e1f083fccebf977ee7f747001428dc9da /src/test/codegen
parent0b2c356420c155373d312f4b7063fd19983dfd20 (diff)
downloadrust-ed5015939f02ce340bf3581c866f7b6ddabb6daf.tar.gz
rust-ed5015939f02ce340bf3581c866f7b6ddabb6daf.zip
Expand .zip() specialization to .map() and .cloned()
Implement .zip() specialization for Map and Cloned.

The crucial thing for transparent specialization is that we want to
preserve the potential side effects.

The simplest example is that in this code snippet:

`(0..6).map(f).zip((0..4).map(g)).count()`

`f` will be called five times, and `g` four times. The last time for `f`
is when the other iterator is at its end, so this element is unused.
This side effect can be preserved without disturbing code generation for
simple uses of `.map()`.

The `Zip::next_back()` case is even more complicated, unfortunately.
Diffstat (limited to 'src/test/codegen')
-rw-r--r--src/test/codegen/zip.rs9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/test/codegen/zip.rs b/src/test/codegen/zip.rs
index 6c956364bf8..d0051c5165f 100644
--- a/src/test/codegen/zip.rs
+++ b/src/test/codegen/zip.rs
@@ -20,3 +20,12 @@ pub fn zip_copy(xs: &[u8], ys: &mut [u8]) {
         *y = *x;
     }
 }
+
+// CHECK-LABEL: @zip_copy_mapped
+#[no_mangle]
+pub fn zip_copy_mapped(xs: &[u8], ys: &mut [u8]) {
+// CHECK: memcpy
+    for (x, y) in xs.iter().map(|&x| x).zip(ys) {
+        *y = x;
+    }
+}