Skip to content

Commit

Permalink
Merge pull request #2 from llogiq/clippy
Browse files Browse the repository at this point in the history
fixed some clippy warnings
  • Loading branch information
BurntSushi authored Aug 2, 2016
2 parents 427354d + 5214ae9 commit 99e7b31
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
16 changes: 8 additions & 8 deletions src/compress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ impl<'s, 'd> Block<'s, 'd> {
}
// If we can squeeze the last copy into a copy 1 operation, do it.
if len <= 11 && offset <= 2047 {
self.dst[self.d + 0] =
self.dst[self.d] =
(((offset >> 8) as u8) << 5)
| (((len - 4) as u8) << 2)
| (Tag::Copy1 as u8);
Expand All @@ -362,7 +362,7 @@ impl<'s, 'd> Block<'s, 'd> {
fn emit_copy2(&mut self, offset: usize, len: usize) {
debug_assert!(1 <= offset && offset <= 65535);
debug_assert!(1 <= len && len <= 64);
self.dst[self.d + 0] = (((len - 1) as u8) << 2) | (Tag::Copy2 as u8);
self.dst[self.d] = (((len - 1) as u8) << 2) | (Tag::Copy2 as u8);
LE::write_u16(&mut self.dst[self.d + 1..], offset as u16);
self.d += 3;
}
Expand Down Expand Up @@ -434,7 +434,7 @@ impl<'s, 'd> Block<'s, 'd> {
let len = lit_end - lit_start;
let n = len.checked_sub(1).unwrap();
if n <= 59 {
self.dst[self.d + 0] = ((n as u8) << 2) | (Tag::Literal as u8);
self.dst[self.d] = ((n as u8) << 2) | (Tag::Literal as u8);
self.d += 1;
if len <= 16 && lit_start + 16 <= self.src.len() {
// SAFETY: lit_start is equivalent to self.next_emit, which
Expand All @@ -452,11 +452,11 @@ impl<'s, 'd> Block<'s, 'd> {
return;
}
} else if n < 256 {
self.dst[self.d + 0] = (60 << 2) | (Tag::Literal as u8);
self.dst[self.d] = (60 << 2) | (Tag::Literal as u8);
self.dst[self.d + 1] = n as u8;
self.d += 2;
} else {
self.dst[self.d + 0] = (61 << 2) | (Tag::Literal as u8);
self.dst[self.d] = (61 << 2) | (Tag::Literal as u8);
LE::write_u16(&mut self.dst[self.d + 1..], n as u16);
self.d += 3;
}
Expand All @@ -474,9 +474,9 @@ impl<'s, 'd> Block<'s, 'd> {
}
}

/// BlockTable is a map from 4 byte sequences to positions of their most recent
/// occurrence in a block. In particular, this table lets us quickly find
/// candidates for compression.
/// `BlockTable` is a map from 4 byte sequences to positions of their most
/// recent occurrence in a block. In particular, this table lets us quickly
/// find candidates for compression.
///
/// We expose the `hash` method so that callers can be fastidious about the
/// number of times a hash is computed.
Expand Down
22 changes: 11 additions & 11 deletions src/crc32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fn crc32c_slice16(mut buf: &[u8]) -> u32 {
let tab16 = &*TABLE16;
let mut crc: u32 = !0;
while buf.len() >= 16 {
crc = crc ^ LE::read_u32(&buf[0..4]);
crc ^= LE::read_u32(&buf[0..4]);
crc = tab16[0][buf[15] as usize]
^ tab16[1][buf[14] as usize]
^ tab16[2][buf[13] as usize]
Expand All @@ -69,8 +69,8 @@ fn crc32c_slice16(mut buf: &[u8]) -> u32 {
^ tab16[11][buf[4] as usize]
^ tab16[12][(crc >> 24) as u8 as usize]
^ tab16[13][(crc >> 16) as u8 as usize]
^ tab16[14][(crc >> 8) as u8 as usize]
^ tab16[15][(crc >> 0) as u8 as usize];
^ tab16[14][(crc >> 8 ) as u8 as usize]
^ tab16[15][(crc ) as u8 as usize];
buf = &buf[16..];
}
for &b in buf {
Expand All @@ -85,15 +85,15 @@ fn crc32c_slice8(mut buf: &[u8]) -> u32 {
let tab8 = &*TABLE16;
let mut crc: u32 = !0;
while buf.len() >= 8 {
crc = crc ^ LE::read_u32(&buf[0..4]);
crc ^= LE::read_u32(&buf[0..4]);
crc = tab8[0][buf[7] as usize]
^ tab8[1][buf[6] as usize]
^ tab8[2][buf[5] as usize]
^ tab8[3][buf[4] as usize]
^ tab8[4][(crc >> 24) as u8 as usize]
^ tab8[5][(crc >> 16) as u8 as usize]
^ tab8[6][(crc >> 8) as u8 as usize]
^ tab8[7][(crc >> 0) as u8 as usize];
^ tab8[6][(crc >> 8 ) as u8 as usize]
^ tab8[7][(crc ) as u8 as usize];
buf = &buf[8..];
}
for &b in buf {
Expand All @@ -108,11 +108,11 @@ fn crc32c_slice4(mut buf: &[u8]) -> u32 {
let tab4 = &*TABLE16;
let mut crc: u32 = !0;
while buf.len() >= 4 {
crc = crc ^ LE::read_u32(&buf[0..4]);
crc ^= LE::read_u32(&buf[0..4]);
crc = tab4[0][(crc >> 24) as u8 as usize]
^ tab4[1][(crc >> 16) as u8 as usize]
^ tab4[2][(crc >> 8) as u8 as usize]
^ tab4[3][(crc >> 0) as u8 as usize];
^ tab4[2][(crc >> 8 ) as u8 as usize]
^ tab4[3][(crc ) as u8 as usize];
buf = &buf[4..];
}
for &b in buf {
Expand All @@ -135,7 +135,7 @@ fn crc32c_multiple(buf: &[u8]) -> u32 {
fn crc32c_bitwise(buf: &[u8]) -> u32 {
let mut crc: u32 = !0;
for &b in buf {
crc = crc ^ (b as u32);
crc ^= b as u32;
for _ in 0..8 {
crc = (crc >> 1) ^ ((crc & 1) * CASTAGNOLI_POLY);
}
Expand All @@ -151,7 +151,7 @@ fn make_table(poly: u32) -> [u32; 256] {
if crc & 1 == 1 {
crc = (crc >> 1) ^ poly;
} else {
crc = crc >> 1;
crc >>= 1;
}
}
tab[i as usize] = crc;
Expand Down
4 changes: 2 additions & 2 deletions src/decompress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use MAX_INPUT_SIZE;
/// tag byte.
const TAG_LOOKUP_TABLE: TagLookupTable = TagLookupTable(tag::TAG_LOOKUP_TABLE);

/// WORD_MASK is a map from the size of an integer in bytes to its
/// `WORD_MASK` is a map from the size of an integer in bytes to its
/// corresponding on a 32 bit integer. This is used when we need to read an
/// integer and we know there are at least 4 bytes to read from a buffer. In
/// this case, we can read a 32 bit little endian integer and mask out only the
Expand Down Expand Up @@ -407,7 +407,7 @@ impl TagLookupTable {

/// Represents a single entry in the tag lookup table.
///
/// See the documentation in TagLookupTable for the bit layout.
/// See the documentation in `TagLookupTable` for the bit layout.
///
/// The type is a `usize` for convenience.
struct TagEntry(usize);
Expand Down
6 changes: 3 additions & 3 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::result;
/// A convenient type alias for `Result<T, snap::Error>`.
pub type Result<T> = result::Result<T, Error>;

/// IntoInnerError occurs when consuming a `Writer` fails.
/// `IntoInnerError` occurs when consuming a `Writer` fails.
///
/// Consuming the `Writer` causes a flush to happen. If the flush fails, then
/// this error is returned, which contains both the original `Writer` and
Expand All @@ -18,7 +18,7 @@ pub struct IntoInnerError<W> {
err: io::Error,
}

/// Creates a new IntoInnerError.
/// Creates a new `IntoInnerError`.
///
/// (This is a visibility hack. It's public in this module, but not in the
/// crate.)
Expand Down Expand Up @@ -208,7 +208,7 @@ impl PartialEq for Error {
&BufferTooSmall { given: given2, min: min2 }) => {
(given1, min1) == (given2, min2)
}
(&Empty, &Empty) => true,
(&Empty, &Empty) |
(&Header, &Header) => true,
(&HeaderMismatch { expected_len: elen1, got_len: glen1 },
&HeaderMismatch { expected_len: elen2, got_len: glen2 }) => {
Expand Down

0 comments on commit 99e7b31

Please sign in to comment.