##// END OF EJS Templates
hg-core: use `u32` instead of `i32` in `Chunk` (D8958#inline-15001 followup)...
Antoine cezar -
r46171:d07e4656 default
parent child Browse files
Show More
@@ -10,9 +10,9 b' use byteorder::{BigEndian, ByteOrder};'
10 #[derive(Debug, Clone)]
10 #[derive(Debug, Clone)]
11 struct Chunk<'a> {
11 struct Chunk<'a> {
12 /// The start position of the chunk of data to replace
12 /// The start position of the chunk of data to replace
13 start: i32,
13 start: u32,
14 /// The end position of the chunk of data to replace (open end interval)
14 /// The end position of the chunk of data to replace (open end interval)
15 end: i32,
15 end: u32,
16 /// The data replacing the chunk
16 /// The data replacing the chunk
17 data: &'a [u8],
17 data: &'a [u8],
18 }
18 }
@@ -22,26 +22,28 b" impl<'a> Chunk<'a> {"
22 ///
22 ///
23 /// Offset allow to take into account the growth/shrinkage of data
23 /// Offset allow to take 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) -> i32 {
25 fn start_offseted_by(&self, offset: i32) -> u32 {
26 self.start + offset
26 let start = self.start as i32 + offset;
27 assert!(start >= 0, "negative chunk start should never happen");
28 start as u32
27 }
29 }
28
30
29 /// Adjusted end of the chunk to replace.
31 /// Adjusted end of the chunk to replace.
30 ///
32 ///
31 /// Offset allow to take into account the growth/shrinkage of data
33 /// Offset allow to take into account the growth/shrinkage of data
32 /// induced by previously applied chunks.
34 /// induced by previously applied chunks.
33 fn end_offseted_by(&self, offset: i32) -> i32 {
35 fn end_offseted_by(&self, offset: i32) -> u32 {
34 self.start_offseted_by(offset) + (self.data.len() as i32)
36 self.start_offseted_by(offset) + self.data.len() as u32
35 }
37 }
36
38
37 /// Length of the replaced chunk.
39 /// Length of the replaced chunk.
38 fn replaced_len(&self) -> i32 {
40 fn replaced_len(&self) -> u32 {
39 self.end - self.start
41 self.end - self.start
40 }
42 }
41
43
42 /// Length difference between the replacing data and the replaced data.
44 /// Length difference between the replacing data and the replaced data.
43 fn len_diff(&self) -> i32 {
45 fn len_diff(&self) -> i32 {
44 (self.data.len() as i32) - self.replaced_len()
46 self.data.len() as i32 - self.replaced_len() as i32
45 }
47 }
46 }
48 }
47
49
@@ -63,10 +65,10 b" impl<'a> PatchList<'a> {"
63 let mut chunks = vec![];
65 let mut chunks = vec![];
64 let mut data = data;
66 let mut data = data;
65 while !data.is_empty() {
67 while !data.is_empty() {
66 let start = BigEndian::read_i32(&data[0..]);
68 let start = BigEndian::read_u32(&data[0..]);
67 let end = BigEndian::read_i32(&data[4..]);
69 let end = BigEndian::read_u32(&data[4..]);
68 let len = BigEndian::read_i32(&data[8..]);
70 let len = BigEndian::read_u32(&data[8..]);
69 assert!(0 <= start && start <= end && len >= 0);
71 assert!(start <= end);
70 chunks.push(Chunk {
72 chunks.push(Chunk {
71 start,
73 start,
72 end,
74 end,
@@ -187,13 +189,13 b" impl<'a> PatchList<'a> {"
187
189
188 first.data = &first.data[(how_much_to_discard as usize)..];
190 first.data = &first.data[(how_much_to_discard as usize)..];
189
191
190 next_offset += how_much_to_discard;
192 next_offset += how_much_to_discard as i32;
191 }
193 }
192
194
193 // Add the chunk of `other` with adjusted position.
195 // Add the chunk of `other` with adjusted position.
194 chunks.push(Chunk {
196 chunks.push(Chunk {
195 start: *start - offset,
197 start: (*start as i32 - offset) as u32,
196 end: *end - next_offset,
198 end: (*end as i32 - next_offset) as u32,
197 data,
199 data,
198 });
200 });
199
201
General Comments 0
You need to be logged in to leave comments. Login now