Skip to content

Commit c66e882

Browse files
committed
Auto merge of #31013 - nrc:fmt-rbml, r=sfackler
2 parents 7a7307e + 8863d37 commit c66e882

File tree

3 files changed

+505
-450
lines changed

3 files changed

+505
-450
lines changed

src/librbml/leb128.rs

+8-19
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
// except according to those terms.
1010

1111
#[inline]
12-
pub fn write_to_vec(vec: &mut Vec<u8>, position: &mut usize, byte: u8)
13-
{
12+
pub fn write_to_vec(vec: &mut Vec<u8>, position: &mut usize, byte: u8) {
1413
if *position == vec.len() {
1514
vec.push(byte);
1615
} else {
@@ -20,13 +19,9 @@ pub fn write_to_vec(vec: &mut Vec<u8>, position: &mut usize, byte: u8)
2019
*position += 1;
2120
}
2221

23-
pub fn write_unsigned_leb128(out: &mut Vec<u8>,
24-
start_position: usize,
25-
mut value: u64)
26-
-> usize {
22+
pub fn write_unsigned_leb128(out: &mut Vec<u8>, start_position: usize, mut value: u64) -> usize {
2723
let mut position = start_position;
28-
loop
29-
{
24+
loop {
3025
let mut byte = (value & 0x7F) as u8;
3126
value >>= 7;
3227
if value != 0 {
@@ -43,9 +38,7 @@ pub fn write_unsigned_leb128(out: &mut Vec<u8>,
4338
return position - start_position;
4439
}
4540

46-
pub fn read_unsigned_leb128(data: &[u8],
47-
start_position: usize)
48-
-> (u64, usize) {
41+
pub fn read_unsigned_leb128(data: &[u8], start_position: usize) -> (u64, usize) {
4942
let mut result = 0;
5043
let mut shift = 0;
5144
let mut position = start_position;
@@ -63,15 +56,13 @@ pub fn read_unsigned_leb128(data: &[u8],
6356
}
6457

6558

66-
pub fn write_signed_leb128(out: &mut Vec<u8>,
67-
start_position: usize,
68-
mut value: i64) -> usize {
59+
pub fn write_signed_leb128(out: &mut Vec<u8>, start_position: usize, mut value: i64) -> usize {
6960
let mut position = start_position;
7061

7162
loop {
7263
let mut byte = (value as u8) & 0x7f;
7364
value >>= 7;
74-
let more = !((((value == 0 ) && ((byte & 0x40) == 0)) ||
65+
let more = !((((value == 0) && ((byte & 0x40) == 0)) ||
7566
((value == -1) && ((byte & 0x40) != 0))));
7667
if more {
7768
byte |= 0x80; // Mark this byte to show that more bytes will follow.
@@ -87,9 +78,7 @@ pub fn write_signed_leb128(out: &mut Vec<u8>,
8778
return position - start_position;
8879
}
8980

90-
pub fn read_signed_leb128(data: &[u8],
91-
start_position: usize)
92-
-> (i64, usize) {
81+
pub fn read_signed_leb128(data: &[u8], start_position: usize) -> (i64, usize) {
9382
let mut result = 0;
9483
let mut shift = 0;
9584
let mut position = start_position;
@@ -107,7 +96,7 @@ pub fn read_signed_leb128(data: &[u8],
10796
}
10897

10998
if (shift < 64) && ((byte & 0x40) != 0) {
110-
/* sign extend */
99+
// sign extend
111100
result |= -(1i64 << shift);
112101
}
113102

0 commit comments

Comments
 (0)