diff options
| author | Ulrik Sverdrup <bluss@users.noreply.github.com> | 2016-10-17 10:58:21 +0200 |
|---|---|---|
| committer | Ulrik Sverdrup <bluss@users.noreply.github.com> | 2016-10-17 10:58:21 +0200 |
| commit | ed5015939f02ce340bf3581c866f7b6ddabb6daf (patch) | |
| tree | 476af78e1f083fccebf977ee7f747001428dc9da /src/test/codegen | |
| parent | 0b2c356420c155373d312f4b7063fd19983dfd20 (diff) | |
| download | rust-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.rs | 9 |
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; + } +} |
