##// END OF EJS Templates
hg-core: renaming of `Chunk` offset methods (D8958#inline-15002 followup)...
Antoine cezar -
r46174:b68b1910 default
parent child Browse files
Show More
@@ -22,7 +22,7 b" impl Chunk<'_> {"
22 ///
22 ///
23 /// The offset, taking into account the growth/shrinkage of data
23 /// The offset, taking into account the growth/shrinkage of data
24 /// induced by previously applied chunks.
24 /// induced by previously applied chunks.
25 fn start_offseted_by(&self, offset: i32) -> u32 {
25 fn start_offset_by(&self, offset: i32) -> u32 {
26 let start = self.start as i32 + offset;
26 let start = self.start as i32 + offset;
27 assert!(start >= 0, "negative chunk start should never happen");
27 assert!(start >= 0, "negative chunk start should never happen");
28 start as u32
28 start as u32
@@ -32,8 +32,8 b" impl Chunk<'_> {"
32 ///
32 ///
33 /// The offset, taking into account the growth/shrinkage of data
33 /// The offset, taking into account the growth/shrinkage of data
34 /// induced by previously applied chunks.
34 /// induced by previously applied chunks.
35 fn end_offseted_by(&self, offset: i32) -> u32 {
35 fn end_offset_by(&self, offset: i32) -> u32 {
36 self.start_offseted_by(offset) + self.data.len() as u32
36 self.start_offset_by(offset) + self.data.len() as u32
37 }
37 }
38
38
39 /// Length of the replaced chunk.
39 /// Length of the replaced chunk.
@@ -122,7 +122,7 b" impl<'a> PatchList<'a> {"
122 // Add chunks of `self` that start before this chunk of `other`
122 // Add chunks of `self` that start before this chunk of `other`
123 // without overlap.
123 // without overlap.
124 while pos < self.chunks.len()
124 while pos < self.chunks.len()
125 && self.chunks[pos].end_offseted_by(offset) <= *start
125 && self.chunks[pos].end_offset_by(offset) <= *start
126 {
126 {
127 let first = self.chunks[pos].clone();
127 let first = self.chunks[pos].clone();
128 offset += first.len_diff();
128 offset += first.len_diff();
@@ -135,12 +135,12 b" impl<'a> PatchList<'a> {"
135 // The left-most part of data is added as an insertion chunk.
135 // The left-most part of data is added as an insertion chunk.
136 // The right-most part data is kept in the chunk.
136 // The right-most part data is kept in the chunk.
137 if pos < self.chunks.len()
137 if pos < self.chunks.len()
138 && self.chunks[pos].start_offseted_by(offset) < *start
138 && self.chunks[pos].start_offset_by(offset) < *start
139 {
139 {
140 let first = &mut self.chunks[pos];
140 let first = &mut self.chunks[pos];
141
141
142 let (data_left, data_right) = first.data.split_at(
142 let (data_left, data_right) = first.data.split_at(
143 (*start - first.start_offseted_by(offset)) as usize,
143 (*start - first.start_offset_by(offset)) as usize,
144 );
144 );
145 let left = Chunk {
145 let left = Chunk {
146 start: first.start,
146 start: first.start,
@@ -170,7 +170,7 b" impl<'a> PatchList<'a> {"
170 // Discard the chunks of `self` that are totally overridden
170 // Discard the chunks of `self` that are totally overridden
171 // by the current chunk of `other`
171 // by the current chunk of `other`
172 while pos < self.chunks.len()
172 while pos < self.chunks.len()
173 && self.chunks[pos].end_offseted_by(next_offset) <= *end
173 && self.chunks[pos].end_offset_by(next_offset) <= *end
174 {
174 {
175 let first = &self.chunks[pos];
175 let first = &self.chunks[pos];
176 next_offset += first.len_diff();
176 next_offset += first.len_diff();
@@ -180,12 +180,12 b" impl<'a> PatchList<'a> {"
180 // Truncate the left-most part of chunk of `self` that overlaps
180 // Truncate the left-most part of chunk of `self` that overlaps
181 // the current chunk of `other`.
181 // the current chunk of `other`.
182 if pos < self.chunks.len()
182 if pos < self.chunks.len()
183 && self.chunks[pos].start_offseted_by(next_offset) < *end
183 && self.chunks[pos].start_offset_by(next_offset) < *end
184 {
184 {
185 let first = &mut self.chunks[pos];
185 let first = &mut self.chunks[pos];
186
186
187 let how_much_to_discard =
187 let how_much_to_discard =
188 *end - first.start_offseted_by(next_offset);
188 *end - first.start_offset_by(next_offset);
189
189
190 first.data = &first.data[(how_much_to_discard as usize)..];
190 first.data = &first.data[(how_much_to_discard as usize)..];
191
191
General Comments 0
You need to be logged in to leave comments. Login now