[Updated] D9102: hg-core: use `u32` instead of `i32` in `Chunk` (D8958#inline-15001 followup)
Phabricator
phabricator at mercurial-scm.org
Tue Sep 29 17:52:27 UTC 2020
Closed by commit rHGd07e4656ff5a: hg-core: use `u32` instead of `i32` in `Chunk` (D8958#inline-15001 followup) (authored by Antoine cezar <acezar at chwitlabs.fr>).
This revision was automatically updated to reflect the committed changes.
This revision was not accepted when it landed; it landed in state "Needs Review".
REPOSITORY
rHG Mercurial
CHANGES SINCE LAST UPDATE
https://phab.mercurial-scm.org/D9102?vs=22912&id=22931
CHANGES SINCE LAST ACTION
https://phab.mercurial-scm.org/D9102/new/
REVISION DETAIL
https://phab.mercurial-scm.org/D9102
AFFECTED FILES
rust/hg-core/src/revlog/patch.rs
CHANGE DETAILS
diff --git a/rust/hg-core/src/revlog/patch.rs b/rust/hg-core/src/revlog/patch.rs
--- a/rust/hg-core/src/revlog/patch.rs
+++ b/rust/hg-core/src/revlog/patch.rs
@@ -10,9 +10,9 @@
#[derive(Debug, Clone)]
struct Chunk<'a> {
/// The start position of the chunk of data to replace
- start: i32,
+ start: u32,
/// The end position of the chunk of data to replace (open end interval)
- end: i32,
+ end: u32,
/// The data replacing the chunk
data: &'a [u8],
}
@@ -22,26 +22,28 @@
///
/// Offset allow to take into account the growth/shrinkage of data
/// induced by previously applied chunks.
- fn start_offseted_by(&self, offset: i32) -> i32 {
- self.start + offset
+ fn start_offseted_by(&self, offset: i32) -> u32 {
+ let start = self.start as i32 + offset;
+ assert!(start >= 0, "negative chunk start should never happen");
+ start as u32
}
/// Adjusted end of the chunk to replace.
///
/// Offset allow to take into account the growth/shrinkage of data
/// induced by previously applied chunks.
- fn end_offseted_by(&self, offset: i32) -> i32 {
- self.start_offseted_by(offset) + (self.data.len() as i32)
+ fn end_offseted_by(&self, offset: i32) -> u32 {
+ self.start_offseted_by(offset) + self.data.len() as u32
}
/// Length of the replaced chunk.
- fn replaced_len(&self) -> i32 {
+ fn replaced_len(&self) -> u32 {
self.end - self.start
}
/// Length difference between the replacing data and the replaced data.
fn len_diff(&self) -> i32 {
- (self.data.len() as i32) - self.replaced_len()
+ self.data.len() as i32 - self.replaced_len() as i32
}
}
@@ -63,10 +65,10 @@
let mut chunks = vec![];
let mut data = data;
while !data.is_empty() {
- let start = BigEndian::read_i32(&data[0..]);
- let end = BigEndian::read_i32(&data[4..]);
- let len = BigEndian::read_i32(&data[8..]);
- assert!(0 <= start && start <= end && len >= 0);
+ let start = BigEndian::read_u32(&data[0..]);
+ let end = BigEndian::read_u32(&data[4..]);
+ let len = BigEndian::read_u32(&data[8..]);
+ assert!(start <= end);
chunks.push(Chunk {
start,
end,
@@ -187,13 +189,13 @@
first.data = &first.data[(how_much_to_discard as usize)..];
- next_offset += how_much_to_discard;
+ next_offset += how_much_to_discard as i32;
}
// Add the chunk of `other` with adjusted position.
chunks.push(Chunk {
- start: *start - offset,
- end: *end - next_offset,
+ start: (*start as i32 - offset) as u32,
+ end: (*end as i32 - next_offset) as u32,
data,
});
To: acezar, #hg-reviewers
Cc: martinvonz, Alphare, mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-patches/attachments/20200929/77496e95/attachment-0002.html>
More information about the Mercurial-patches
mailing list