File tree Expand file tree Collapse file tree 2 files changed +14
-8
lines changed
Expand file tree Collapse file tree 2 files changed +14
-8
lines changed Original file line number Diff line number Diff line change @@ -43,7 +43,7 @@ include = [
4343 " README.md" ,
4444]
4545edition = " 2021"
46- rust-version = " 1.82 "
46+ rust-version = " 1.84 "
4747readme = " README.md"
4848categories = [" database-implementations" , " data-structures" , " compression" ]
4949
Original file line number Diff line number Diff line change @@ -423,19 +423,25 @@ impl<T> Extend<T> for BufferMut<T> {
423423
424424 let remaining = self . capacity ( ) - self . len ( ) ;
425425
426- let dst: * mut T = self . bytes . spare_capacity_mut ( ) . as_mut_ptr ( ) . cast ( ) ;
427- let mut consumed = 0 ;
428- while consumed < remaining {
426+ let begin: * const T = self . bytes . spare_capacity_mut ( ) . as_mut_ptr ( ) . cast ( ) ;
427+ let mut dst: * mut T = begin. cast_mut ( ) ;
428+ let buffer_end: * const T = unsafe { dst. add ( remaining) } ;
429+ while dst. addr ( ) < buffer_end. addr ( ) {
429430 if let Some ( item) = iterator. next ( ) {
430- // SAFETY: We know we have enough capacity to write the item.
431- unsafe { dst. add ( consumed) . write ( item) } ;
432- consumed += 1 ;
431+ unsafe {
432+ // SAFETY: We know we have enough capacity to write the item.
433+ dst. write ( item) ;
434+ // Note. we used to have dst.add(iteration).write(item), here.
435+ // however this was much slower than just incrementing dst.
436+ dst = dst. add ( 1 ) ;
437+ }
433438 } else {
434439 break ;
435440 }
436441 }
437442
438- self . length += consumed;
443+ // TODO(joe): replace with ptr_sub when stable
444+ self . length += unsafe { dst. byte_offset_from ( begin) as usize / size_of :: < T > ( ) } ;
439445 unsafe { self . bytes . set_len ( self . length * size_of :: < T > ( ) ) } ;
440446
441447 iterator. for_each ( |item| self . push ( item) ) ;
You can’t perform that action at this time.
0 commit comments