bupsplit: rustfmt(*)
authorColin Walters <walters@verbum.org>
Sun, 31 May 2020 17:58:44 +0000 (17:58 +0000)
committerColin Walters <walters@verbum.org>
Mon, 1 Jun 2020 13:53:55 +0000 (13:53 +0000)
Let's use the standard rustfmt style.
Also remove unused parenthesis which rust-analyzer was complaining
about.

Also add a `.gitignore`.

rust/.gitignore [new file with mode: 0644]
rust/src/bupsplit.rs

diff --git a/rust/.gitignore b/rust/.gitignore
new file mode 100644 (file)
index 0000000..1e7caa9
--- /dev/null
@@ -0,0 +1,2 @@
+Cargo.lock
+target/
index 607c66390cc4030b368ac8d798ab0ce29c09af7b..73dc9ee184b89a9f784369e2f7ad796a9d5301bd 100644 (file)
@@ -43,9 +43,9 @@ const ROLLSUM_CHAR_OFFSET: u32 = 31;
 
 // Previously in the header file
 const BUP_BLOBBITS: u32 = 13;
-const BUP_BLOBSIZE: u32 = (1<<BUP_BLOBBITS);
+const BUP_BLOBSIZE: u32 = 1 << BUP_BLOBBITS;
 const BUP_WINDOWBITS: u32 = 7;
-const BUP_WINDOWSIZE: u32 = (1<<(BUP_WINDOWBITS-1));
+const BUP_WINDOWSIZE: u32 = 1 << BUP_WINDOWBITS - 1;
 
 struct Rollsum {
     s1: u32,
@@ -56,10 +56,11 @@ struct Rollsum {
 
 impl Rollsum {
     pub fn new() -> Rollsum {
-        Rollsum { s1: BUP_WINDOWSIZE * ROLLSUM_CHAR_OFFSET,
-                  s2: BUP_WINDOWSIZE * (BUP_WINDOWSIZE-1) * ROLLSUM_CHAR_OFFSET,
-                  window: [0; 64],
-                  wofs: 0
+        Rollsum {
+            s1: BUP_WINDOWSIZE * ROLLSUM_CHAR_OFFSET,
+            s2: BUP_WINDOWSIZE * (BUP_WINDOWSIZE - 1) * ROLLSUM_CHAR_OFFSET,
+            window: [0; 64],
+            wofs: 0,
         }
     }
 
@@ -67,8 +68,13 @@ impl Rollsum {
     pub fn add(&mut self, drop: u8, add: u8) -> () {
         let drop_expanded = u32::from(drop);
         let add_expanded = u32::from(add);
-        self.s1 = self.s1.wrapping_add(add_expanded.wrapping_sub(drop_expanded));
-        self.s2 = self.s2.wrapping_add(self.s1.wrapping_sub(BUP_WINDOWSIZE * (drop_expanded + ROLLSUM_CHAR_OFFSET)));
+        self.s1 = self
+            .s1
+            .wrapping_add(add_expanded.wrapping_sub(drop_expanded));
+        self.s2 = self.s2.wrapping_add(
+            self.s1
+                .wrapping_sub(BUP_WINDOWSIZE * (drop_expanded + ROLLSUM_CHAR_OFFSET)),
+        );
     }
 
     pub fn roll(&mut self, ch: u8) -> () {
@@ -85,7 +91,7 @@ impl Rollsum {
 }
 
 #[no_mangle]
-pub extern fn bupsplit_sum(buf: *const u8, ofs: libc::size_t, len: libc::size_t) -> u32 {
+pub extern "C" fn bupsplit_sum(buf: *const u8, ofs: libc::size_t, len: libc::size_t) -> u32 {
     let sbuf = unsafe {
         assert!(!buf.is_null());
         slice::from_raw_parts(buf.offset(ofs as isize), (len - ofs) as usize)
@@ -99,9 +105,11 @@ pub extern fn bupsplit_sum(buf: *const u8, ofs: libc::size_t, len: libc::size_t)
 }
 
 #[no_mangle]
-pub extern fn bupsplit_find_ofs(buf: *const u8, len: libc::size_t,
-                                bits: *mut libc::c_int) -> libc::c_int
-{
+pub extern "C" fn bupsplit_find_ofs(
+    buf: *const u8,
+    len: libc::size_t,
+    bits: *mut libc::c_int,
+) -> libc::c_int {
     if buf.is_null() {
         return 0;
     }
@@ -110,10 +118,10 @@ pub extern fn bupsplit_find_ofs(buf: *const u8, len: libc::size_t,
     let mut r = Rollsum::new();
     for x in sbuf {
         r.roll(*x);
-             if (r.s2 & (BUP_BLOBSIZE-1)) == ((u32::max_value()) & (BUP_BLOBSIZE-1)) {
-                 if !bits.is_null() {
+        if (r.s2 & (BUP_BLOBSIZE - 1)) == ((u32::max_value()) & (BUP_BLOBSIZE - 1)) {
+            if !bits.is_null() {
                 let mut sum = r.digest() >> BUP_BLOBBITS;
-                let mut rbits : libc::c_int = BUP_BLOBBITS as i32;
+                let mut rbits: libc::c_int = BUP_BLOBBITS as i32;
                 while sum & 1 != 0 {
                     sum >>= 1;
                     rbits += 1;
@@ -122,7 +130,7 @@ pub extern fn bupsplit_find_ofs(buf: *const u8, len: libc::size_t,
                     *bits = rbits;
                 }
             }
-            return len as i32
+            return len as i32;
         }
     }
     0