@@ -1475,20 +1475,22 @@ pub mod string {
14751475 fn extend_from_self ( & mut self , other : Self :: Borrowed < ' _ > , range : std:: ops:: Range < usize > ) {
14761476 if !range. is_empty ( ) {
14771477 // Imported bounds will be relative to this starting offset.
1478- let mut values_len = self . values . len ( ) as u64 ;
1478+ let values_len = self . values . len ( ) as u64 ;
14791479
14801480 // Push all bytes that we can, all at once.
1481- let other_lower: usize = if range. start == 0 { 0 } else { other. bounds . index_as ( range. start -1 ) } as usize ;
1482- let other_upper: usize = other. bounds . index_as ( range. end -1 ) as usize ;
1481+ let other_lower = if range. start == 0 { 0 } else { other. bounds . index_as ( range. start -1 ) } ;
1482+ let other_upper = other. bounds . index_as ( range. end -1 ) ;
14831483 self . values . extend_from_self ( other. values , other_lower as usize .. other_upper as usize ) ;
14841484
1485- // Determine new bounds to push based on lengths, relative to `values_len`.
1486- let mut lower = other_lower as u64 ;
1487- for index in range {
1488- let upper = other. bounds . index_as ( index) ;
1489- values_len += upper - lower;
1490- self . bounds . push ( & values_len) ;
1491- lower = upper;
1485+ // Each bound needs to be shifted by `values_len - other_lower`.
1486+ if values_len == other_lower {
1487+ self . bounds . extend_from_self ( other. bounds , range) ;
1488+ }
1489+ else {
1490+ for index in range {
1491+ let shifted = other. bounds . index_as ( index) - other_lower + values_len;
1492+ self . bounds . push ( & shifted)
1493+ }
14921494 }
14931495 }
14941496 }
@@ -1690,20 +1692,22 @@ pub mod vector {
16901692 fn extend_from_self ( & mut self , other : Self :: Borrowed < ' _ > , range : std:: ops:: Range < usize > ) {
16911693 if !range. is_empty ( ) {
16921694 // Imported bounds will be relative to this starting offset.
1693- let mut values_len = self . values . len ( ) as u64 ;
1695+ let values_len = self . values . len ( ) as u64 ;
16941696
16951697 // Push all bytes that we can, all at once.
1696- let other_lower: usize = if range. start == 0 { 0 } else { other. bounds . index_as ( range. start -1 ) } as usize ;
1697- let other_upper: usize = other. bounds . index_as ( range. end -1 ) as usize ;
1698+ let other_lower = if range. start == 0 { 0 } else { other. bounds . index_as ( range. start -1 ) } ;
1699+ let other_upper = other. bounds . index_as ( range. end -1 ) ;
16981700 self . values . extend_from_self ( other. values , other_lower as usize .. other_upper as usize ) ;
16991701
1700- // Determine new bounds to push based on lengths, relative to `values_len`.
1701- let mut lower = other_lower as u64 ;
1702- for index in range {
1703- let upper = other. bounds . index_as ( index) ;
1704- values_len += upper - lower;
1705- self . bounds . push ( & values_len) ;
1706- lower = upper;
1702+ // Each bound needs to be shifted by `values_len - other_lower`.
1703+ if values_len == other_lower {
1704+ self . bounds . extend_from_self ( other. bounds , range) ;
1705+ }
1706+ else {
1707+ for index in range {
1708+ let shifted = other. bounds . index_as ( index) - other_lower + values_len;
1709+ self . bounds . push ( & shifted)
1710+ }
17071711 }
17081712 }
17091713 }
0 commit comments