Showing 2 of 3 files from the diff.
Other files ignored by Codecov
Cargo.toml has changed.

@@ -7,19 +7,25 @@
Loading
7 7
    transaction::{Transaction, TxSegCheck},
8 8
};
9 9
use data_encoding::BASE32_DNSSEC;
10 -
use integer_encoding::{VarInt, VarIntReader};
11 10
pub use std::fs::OpenOptions;
12 -
use std::{fmt, io::Cursor, str};
11 +
use std::{fmt, io::Write, str};
12 +
use unsigned_varint::{
13 +
    decode::{u32 as u32_vdec, u64 as u64_vdec},
14 +
    encode::{u32 as u32_venc, u32_buffer, u64 as u64_venc, u64_buffer},
15 +
};
13 16
14 17
fn write_id(f: &mut fmt::Formatter, id: u32) -> fmt::Result {
15 -
    let mut buffer = id.encode_var_vec();
18 +
    let mut buffer = Vec::new();
19 +
    buffer
20 +
        .write_all(u32_venc(id, &mut u32_buffer()))
21 +
        .expect("no failure expected only memory allocation");
16 22
    buffer.push(0b0101_0101);
17 23
    write!(f, "{}", BASE32_DNSSEC.encode(&buffer))
18 24
}
19 25
20 26
fn read_id(s: &str) -> PRes<u32> {
21 27
    let bytes = BASE32_DNSSEC.decode(s.as_bytes())?;
22 -
    VarIntReader::read_varint(&mut Cursor::new(bytes)).map_err(|_| PersyError::InvalidId(String::from(s)))
28 +
    Ok(u32_vdec(&bytes).map_err(|_| PersyError::InvalidId(String::from(s)))?.0)
23 29
}
24 30
25 31
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Debug)]
@@ -37,9 +43,14 @@
Loading
37 43
38 44
impl fmt::Display for RecRef {
39 45
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
40 -
        let mut buffer = self.page.encode_var_vec();
46 +
        let mut buffer = Vec::new();
47 +
        buffer
48 +
            .write_all(u64_venc(self.page, &mut u64_buffer()))
49 +
            .expect("no failure expected only memory allocation");
41 50
        buffer.push(0b0101_0101);
42 -
        buffer.extend_from_slice(&self.pos.encode_var_vec());
51 +
        buffer
52 +
            .write_all(u32_venc(self.pos, &mut u32_buffer()))
53 +
            .expect("no failure expected only memory allocation");
43 54
        write!(f, "{}", BASE32_DNSSEC.encode(&buffer))
44 55
    }
45 56
}
@@ -49,14 +60,8 @@
Loading
49 60
50 61
    fn from_str(s: &str) -> Result<Self, Self::Err> {
51 62
        let bytes = BASE32_DNSSEC.decode(s.as_bytes())?;
52 -
        let mut cursor = Cursor::new(bytes);
53 -
        let page = cursor
54 -
            .read_varint()
55 -
            .map_err(|_| PersyError::InvalidId(String::from(s)))?;
56 -
        cursor.set_position(cursor.position() + 1);
57 -
        let pos = cursor
58 -
            .read_varint()
59 -
            .map_err(|_| PersyError::InvalidId(String::from(s)))?;
63 +
        let (page, rest) = u64_vdec(&bytes).map_err(|_| PersyError::InvalidId(String::from(s)))?;
64 +
        let (pos, _) = u32_vdec(&rest[1..]).map_err(|_| PersyError::InvalidId(String::from(s)))?;
60 65
        Ok(RecRef::new(page, pos))
61 66
    }
62 67
}
@@ -297,8 +302,13 @@
Loading
297 302
298 303
impl fmt::Display for IndexId {
299 304
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
300 -
        let mut buffer = self.meta.encode_var_vec();
301 -
        buffer.extend_from_slice(&self.data.encode_var_vec());
305 +
        let mut buffer = Vec::new();
306 +
        buffer
307 +
            .write_all(u32_venc(self.meta, &mut u32_buffer()))
308 +
            .expect("no failure expected only memory allocation");
309 +
        buffer
310 +
            .write_all(u32_venc(self.data, &mut u32_buffer()))
311 +
            .expect("no failure expected only memory allocation");
302 312
        buffer.push(0b0101_0101);
303 313
        write!(f, "{}", BASE32_DNSSEC.encode(&buffer))
304 314
    }
@@ -309,14 +319,10 @@
Loading
309 319
310 320
    fn from_str(s: &str) -> Result<Self, Self::Err> {
311 321
        let bytes = BASE32_DNSSEC.decode(s.as_bytes())?;
312 -
        let mut cursor = Cursor::new(bytes);
313 -
        let meta = cursor
314 -
            .read_varint()
315 -
            .map_err(|_| PersyError::InvalidId(String::from(s)))?;
316 -
        let data = if cursor.get_ref().len() - cursor.position() as usize > 1 {
317 -
            cursor
318 -
                .read_varint()
319 -
                .map_err(|_| PersyError::InvalidId(String::from(s)))?
322 +
        let (meta, bytes) = u32_vdec(&bytes).map_err(|_| PersyError::InvalidId(String::from(s)))?;
323 +
        let data = if bytes.len() > 1 {
324 +
            let (d, _) = u32_vdec(&bytes).map_err(|_| PersyError::InvalidId(String::from(s)))?;
325 +
            d
320 326
        } else {
321 327
            0
322 328
        };

@@ -1,7 +1,8 @@
Loading
1 1
use crate::PRes;
2 2
use byteorder::{BigEndian, ByteOrder, ReadBytesExt, WriteBytesExt};
3 -
use integer_encoding::VarInt;
4 3
use std::io::{Cursor, Read, Write};
4 +
use unsigned_varint::{encode, io};
5 +
use zigzag::ZigZag;
5 6
6 7
pub trait InfallibleRead {
7 8
    fn read_exact(&mut self, buf: &mut [u8]);
@@ -11,32 +12,21 @@
Loading
11 12
    fn write_all(&mut self, buf: &[u8]);
12 13
}
13 14
14 -
#[allow(dead_code)]
15 -
pub(crate) fn write_varint<V: VarInt, W: InfallibleWrite + ?Sized>(w: &mut W, v: V) {
16 -
    let mut buf = [0 as u8; 10];
17 -
    let b = v.encode_var(&mut buf);
18 -
    w.write_all(&buf[0..b])
15 +
struct InfallibleReadWrapper<'a, T: InfallibleRead + ?Sized> {
16 +
    reader: &'a mut T,
19 17
}
20 18
21 -
// Start of snippet taken from integer-ecoding specialized for InfallibleRead
22 -
pub const MSB: u8 = 0b1000_0000;
23 -
24 19
#[allow(dead_code)]
25 -
pub(crate) fn read_varint<V: VarInt, R: InfallibleRead + ?Sized>(r: &mut R) -> V {
26 -
    let mut int_buf = [0 as u8; 10];
27 -
    let mut int_cursor = 0;
28 -
    let mut buf = [0 as u8; 1];
29 -
30 -
    while int_cursor == 0 || (int_buf[int_cursor - 1] & MSB != 0) {
31 -
        r.read_exact(&mut buf);
32 -
        if int_cursor >= 10 {
33 -
            panic!("Unterminated varint")
34 -
        }
35 -
        int_buf[int_cursor] = buf[0];
36 -
        int_cursor = 0;
20 +
impl<'a, T: InfallibleRead + ?Sized> InfallibleReadWrapper<'a, T> {
21 +
    fn new(reader: &'a mut T) -> Self {
22 +
        InfallibleReadWrapper { reader }
23 +
    }
24 +
}
25 +
impl<'a, T: InfallibleRead + ?Sized> Read for InfallibleReadWrapper<'a, T> {
26 +
    fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
27 +
        InfallibleRead::read_exact(self.reader, buf);
28 +
        Ok(buf.len())
37 29
    }
38 -
39 -
    V::decode_var(&int_buf[0..int_cursor]).0
40 30
}
41 31
42 32
// End of snippet taken from integer-ecoding specialized for InfallibleRead
@@ -44,42 +34,52 @@
Loading
44 34
pub(crate) trait InfallibleReadVarInt: InfallibleRead {
45 35
    #[inline]
46 36
    fn read_u8_varint(&mut self) -> u8 {
47 -
        read_varint(self)
37 +
        io::read_u8(InfallibleReadWrapper::new(self)).expect("infallible")
48 38
    }
49 39
50 40
    #[inline]
51 41
    fn read_u16_varint(&mut self) -> u16 {
52 -
        read_varint(self)
42 +
        io::read_u16(InfallibleReadWrapper::new(self)).expect("infallible")
53 43
    }
54 44
55 45
    #[inline]
56 46
    fn read_u32_varint(&mut self) -> u32 {
57 -
        read_varint(self)
47 +
        io::read_u32(InfallibleReadWrapper::new(self)).expect("infallible")
58 48
    }
59 49
60 50
    #[inline]
61 51
    fn read_u64_varint(&mut self) -> u64 {
62 -
        read_varint(self)
52 +
        io::read_u64(InfallibleReadWrapper::new(self)).expect("infallible")
53 +
    }
54 +
55 +
    #[inline]
56 +
    fn read_u128_varint(&mut self) -> u128 {
57 +
        io::read_u128(InfallibleReadWrapper::new(self)).expect("infallible")
63 58
    }
64 59
65 60
    #[inline]
66 61
    fn read_i8_varint(&mut self) -> i8 {
67 -
        read_varint(self)
62 +
        ZigZag::decode(self.read_u8_varint())
68 63
    }
69 64
70 65
    #[inline]
71 66
    fn read_i16_varint(&mut self) -> i16 {
72 -
        read_varint(self)
67 +
        ZigZag::decode(self.read_u16_varint())
73 68
    }
74 69
75 70
    #[inline]
76 71
    fn read_i32_varint(&mut self) -> i32 {
77 -
        read_varint(self)
72 +
        ZigZag::decode(self.read_u32_varint())
78 73
    }
79 74
80 75
    #[inline]
81 76
    fn read_i64_varint(&mut self) -> i64 {
82 -
        read_varint(self)
77 +
        ZigZag::decode(self.read_u64_varint())
78 +
    }
79 +
80 +
    #[inline]
81 +
    fn read_i128_varint(&mut self) -> i128 {
82 +
        ZigZag::decode(self.read_u128_varint())
83 83
    }
84 84
}
85 85
impl<R: InfallibleRead + ?Sized> InfallibleReadVarInt for R {}
@@ -87,42 +87,52 @@
Loading
87 87
pub(crate) trait InfallibleWriteVarInt: InfallibleWrite {
88 88
    #[inline]
89 89
    fn write_varint_u8(&mut self, value: u8) {
90 -
        write_varint(self, value)
90 +
        self.write_all(encode::u8(value, &mut encode::u8_buffer()));
91 91
    }
92 92
93 93
    #[inline]
94 94
    fn write_varint_u16(&mut self, value: u16) {
95 -
        write_varint(self, value)
95 +
        self.write_all(encode::u16(value, &mut encode::u16_buffer()));
96 96
    }
97 97
98 98
    #[inline]
99 99
    fn write_varint_u32(&mut self, value: u32) {
100 -
        write_varint(self, value)
100 +
        self.write_all(encode::u32(value, &mut encode::u32_buffer()));
101 101
    }
102 102
103 103
    #[inline]
104 104
    fn write_varint_u64(&mut self, value: u64) {
105 -
        write_varint(self, value)
105 +
        self.write_all(encode::u64(value, &mut encode::u64_buffer()));
106 +
    }
107 +
108 +
    #[inline]
109 +
    fn write_varint_u128(&mut self, value: u128) {
110 +
        self.write_all(encode::u128(value, &mut encode::u128_buffer()));
106 111
    }
107 112
108 113
    #[inline]
109 114
    fn write_varint_i8(&mut self, value: i8) {
110 -
        write_varint(self, value)
115 +
        self.write_varint_u8(ZigZag::encode(value))
111 116
    }
112 117
113 118
    #[inline]
114 119
    fn write_varint_i16(&mut self, value: i16) {
115 -
        write_varint(self, value)
120 +
        self.write_varint_u16(ZigZag::encode(value))
116 121
    }
117 122
118 123
    #[inline]
119 124
    fn write_varint_i32(&mut self, value: i32) {
120 -
        write_varint(self, value)
125 +
        self.write_varint_u32(ZigZag::encode(value))
121 126
    }
122 127
123 128
    #[inline]
124 129
    fn write_varint_i64(&mut self, value: i64) {
125 -
        write_varint(self, value)
130 +
        self.write_varint_u64(ZigZag::encode(value))
131 +
    }
132 +
133 +
    #[inline]
134 +
    fn write_varint_i128(&mut self, value: i128) {
135 +
        self.write_varint_u128(ZigZag::encode(value))
126 136
    }
127 137
}
128 138
Files Coverage
src 93.11%
tests 98.56%
Project Totals (29 files) 94.11%
Notifications are pending CI completion. Waiting for GitLab's status webhook to queue notifications. Push notifications now.
1
coverage:
2
  status:
3
    project:
4
      default:
5
        target: 80%
6
        threshold: 1.0%
7
    patch: off
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading