1
Fork 0

Use ExactSizeIterator + TrustedLen instead of num_cases arg for switch

This commit is contained in:
bjorn3 2019-03-29 17:23:52 +01:00
parent 56842b2154
commit 35705dee7e
5 changed files with 7 additions and 6 deletions

View file

@ -21,6 +21,7 @@ use rustc_codegen_ssa::mir::place::PlaceRef;
use std::borrow::Cow; use std::borrow::Cow;
use std::ops::{Deref, Range}; use std::ops::{Deref, Range};
use std::ptr; use std::ptr;
use std::iter::TrustedLen;
// All Builders must have an llfn associated with them // All Builders must have an llfn associated with them
#[must_use] #[must_use]
@ -169,11 +170,10 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
&mut self, &mut self,
v: &'ll Value, v: &'ll Value,
else_llbb: &'ll BasicBlock, else_llbb: &'ll BasicBlock,
num_cases: usize, cases: impl ExactSizeIterator<Item = (u128, &'ll BasicBlock)> + TrustedLen,
cases: impl Iterator<Item = (u128, &'ll BasicBlock)>,
) { ) {
let switch = unsafe { let switch = unsafe {
llvm::LLVMBuildSwitch(self.llbuilder, v, else_llbb, num_cases as c_uint) llvm::LLVMBuildSwitch(self.llbuilder, v, else_llbb, cases.len() as c_uint)
}; };
for (on_val, dest) in cases { for (on_val, dest) in cases {
let on_val = self.const_uint_big(self.val_ty(v), on_val); let on_val = self.const_uint_big(self.val_ty(v), on_val);

View file

@ -20,6 +20,7 @@
#![feature(concat_idents)] #![feature(concat_idents)]
#![feature(link_args)] #![feature(link_args)]
#![feature(static_nobundle)] #![feature(static_nobundle)]
#![feature(trusted_len)]
#![deny(rust_2018_idioms)] #![deny(rust_2018_idioms)]
#![allow(explicit_outlives_requirements)] #![allow(explicit_outlives_requirements)]

View file

@ -10,6 +10,7 @@
#![feature(try_blocks)] #![feature(try_blocks)]
#![feature(in_band_lifetimes)] #![feature(in_band_lifetimes)]
#![feature(nll)] #![feature(nll)]
#![feature(trusted_len)]
#![allow(unused_attributes)] #![allow(unused_attributes)]
#![allow(dead_code)] #![allow(dead_code)]
#![deny(rust_2018_idioms)] #![deny(rust_2018_idioms)]

View file

@ -217,7 +217,6 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
bx.switch( bx.switch(
discr.immediate(), discr.immediate(),
helper.llblock(self, *otherwise), helper.llblock(self, *otherwise),
values.len(),
values.iter().zip(targets).map(|(&value, target)| { values.iter().zip(targets).map(|(&value, target)| {
(value, helper.llblock(self, *target)) (value, helper.llblock(self, *target))
}) })

View file

@ -12,6 +12,7 @@ use crate::MemFlags;
use rustc::ty::Ty; use rustc::ty::Ty;
use rustc::ty::layout::{Align, Size}; use rustc::ty::layout::{Align, Size};
use std::ops::Range; use std::ops::Range;
use std::iter::TrustedLen;
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub enum OverflowOp { pub enum OverflowOp {
@ -49,8 +50,7 @@ pub trait BuilderMethods<'a, 'tcx: 'a>:
&mut self, &mut self,
v: Self::Value, v: Self::Value,
else_llbb: Self::BasicBlock, else_llbb: Self::BasicBlock,
num_cases: usize, cases: impl ExactSizeIterator<Item = (u128, Self::BasicBlock)> + TrustedLen,
cases: impl Iterator<Item = (u128, Self::BasicBlock)>,
); );
fn invoke( fn invoke(
&mut self, &mut self,