@@ -146,7 +146,6 @@ use core::{
146
146
cell:: RefCell ,
147
147
hint:: unreachable_unchecked,
148
148
iter:: { ExactSizeIterator , Iterator } ,
149
- mem:: MaybeUninit ,
150
149
ops:: { Add , Mul } ,
151
150
} ;
152
151
use num_traits:: { One , Zero } ;
@@ -321,7 +320,7 @@ pub trait IteratorILP: Iterator + Sized + TrustedLowerBound {
321
320
for _ in 0 ..stream_len {
322
321
// Fetch one Option<Item> per stream
323
322
let item_opts: [ Option < Self :: Item > ; STREAMS ] =
324
- array_from_fn ( |_| unsafe { next_unchecked ( & mut iter) } ) ;
323
+ core :: array :: from_fn ( |_| unsafe { next_unchecked ( & mut iter) } ) ;
325
324
326
325
// Check if the item of interest was found
327
326
if let Some ( item) = item_opts. into_iter ( ) . flatten ( ) . next ( ) {
@@ -424,7 +423,7 @@ pub trait IteratorILP: Iterator + Sized + TrustedLowerBound {
424
423
assert_ne ! ( STREAMS , 0 , "Need at least one stream to make progress" ) ;
425
424
426
425
// Set up accumulators
427
- let mut accumulators = array_from_fn :: < STREAMS , _ > ( |_| Some ( neutral ( ) ) ) ;
426
+ let mut accumulators: [ Option < Acc > ; STREAMS ] = core :: array :: from_fn ( |_| Some ( neutral ( ) ) ) ;
428
427
let mut accumulate = |accumulator : & mut Option < Acc > , item| {
429
428
if let Some ( prev_acc) = accumulator. take ( ) {
430
429
* accumulator = Some ( accumulate ( prev_acc, item) ) ;
@@ -545,74 +544,6 @@ unsafe fn next_unchecked<Item>(iter: &mut impl Iterator<Item = Item>) -> Item {
545
544
}
546
545
}
547
546
548
- /// Build an array using a mapping from index to value
549
- ///
550
- /// This may look suspiciously like `std::array::from_fn()`, because it is
551
- /// actually a clone of that function. Unfortunately, at the time of
552
- /// writing, the real thing does not optimize well because the compiler fails to
553
- /// inline some steps, so we need to clone it for performance...
554
- #[ inline]
555
- fn array_from_fn < const SIZE : usize , T > ( mut idx_to_elem : impl FnMut ( usize ) -> T ) -> [ T ; SIZE ] {
556
- let mut array = PartialArray :: new ( ) ;
557
- for idx in 0 ..SIZE {
558
- array. push ( idx_to_elem ( idx) ) ;
559
- }
560
- array. collect ( )
561
- }
562
-
563
- /// Partially initialized array
564
- struct PartialArray < T , const N : usize > {
565
- inner : MaybeUninit < [ T ; N ] > ,
566
- num_initialized : usize ,
567
- }
568
- //
569
- impl < T , const N : usize > PartialArray < T , N > {
570
- /// Prepare to iteratively initialize an array
571
- #[ inline]
572
- fn new ( ) -> Self {
573
- Self {
574
- inner : MaybeUninit :: uninit ( ) ,
575
- num_initialized : 0 ,
576
- }
577
- }
578
-
579
- /// Initialize the next array element
580
- #[ inline]
581
- fn push ( & mut self , value : T ) {
582
- assert ! ( self . num_initialized < N ) ;
583
- unsafe {
584
- let ptr = self
585
- . inner
586
- . as_mut_ptr ( )
587
- . cast :: < T > ( )
588
- . add ( self . num_initialized ) ;
589
- ptr. write ( value) ;
590
- self . num_initialized += 1 ;
591
- }
592
- }
593
-
594
- /// Assume the array is fully initialized and collect its value
595
- #[ inline]
596
- fn collect ( self ) -> [ T ; N ] {
597
- assert_eq ! ( self . num_initialized, N ) ;
598
- unsafe {
599
- let result = self . inner . assume_init_read ( ) ;
600
- core:: mem:: forget ( self ) ;
601
- result
602
- }
603
- }
604
- }
605
- //
606
- impl < T , const N : usize > Drop for PartialArray < T , N > {
607
- /// Drop already initialized elements on panic
608
- fn drop ( & mut self ) {
609
- let ptr = self . inner . as_mut_ptr ( ) . cast :: < T > ( ) ;
610
- for idx in 0 ..self . num_initialized {
611
- unsafe { ptr. add ( idx) . drop_in_place ( ) } ;
612
- }
613
- }
614
- }
615
-
616
547
/// An iterator that reports an accurate lower bound using [`size_hint()`]
617
548
///
618
549
/// # Safety
0 commit comments