about summary refs log tree commit diff
path: root/src/test/codegen
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2018-02-07 08:30:53 -0800
committerGitHub <noreply@github.com>2018-02-07 08:30:53 -0800
commitda6dcbc21ebfa62c58352c9129dc1e1b99d9b71f (patch)
treebd0c7b88eca61cc2e3553c2d4479f96c1496e3b2 /src/test/codegen
parent0ba871254e97a72eb5ab43f26b42a943ab5f330d (diff)
parent6caec2c0494a173f696e5a63583ff35d1bd106aa (diff)
downloadrust-da6dcbc21ebfa62c58352c9129dc1e1b99d9b71f.tar.gz
rust-da6dcbc21ebfa62c58352c9129dc1e1b99d9b71f.zip
Rollup merge of #47944 - oberien:unboundediterator-trustedlen, r=bluss
Implement TrustedLen for Take<Repeat> and Take<RangeFrom>

This will allow optimization of simple `repeat(x).take(n).collect()` iterators, which are currently not vectorized and have capacity checks.

This will only support a few aggregates on `Repeat` and `RangeFrom`, which might be enough for simple cases, but doesn't optimize more complex ones. Namely, Cycle, StepBy, Filter, FilterMap, Peekable, SkipWhile, Skip, FlatMap, Fuse and Inspect are not marked `TrustedLen` when the inner iterator is infinite.

Previous discussion can be found in #47082

r? @alexcrichton
Diffstat (limited to 'src/test/codegen')
-rw-r--r--src/test/codegen/repeat-trusted-len.rs23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/test/codegen/repeat-trusted-len.rs b/src/test/codegen/repeat-trusted-len.rs
new file mode 100644
index 00000000000..43872f15d51
--- /dev/null
+++ b/src/test/codegen/repeat-trusted-len.rs
@@ -0,0 +1,23 @@
+// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// compile-flags: -O
+// ignore-tidy-linelength
+
+#![crate_type = "lib"]
+
+use std::iter;
+
+// CHECK-LABEL: @repeat_take_collect
+#[no_mangle]
+pub fn repeat_take_collect() -> Vec<u8> {
+// CHECK: call void @llvm.memset.p0i8
+    iter::repeat(42).take(100000).collect()
+}