Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
Signed-off-by: Breezewish <breezewish@pingcap.com>
  • Loading branch information
breezewish committed May 10, 2019
1 parent 246230e commit 3c1bbd1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
5 changes: 1 addition & 4 deletions components/codec/src/byte.rs
Expand Up @@ -439,10 +439,7 @@ impl CompactByteCodec {
Err(_) => encoded.len(),
Ok((value, decoded_n)) => {
let r = value as usize + decoded_n;
if unsafe { unlikely(r > encoded.len()) } {
return encoded.len();
}
r
r.min(encoded.len())
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions components/codec/src/number.rs
Expand Up @@ -483,7 +483,8 @@ impl NumberCodec {
pub fn try_decode_var_i64(buf: &[u8]) -> Result<(i64, usize)> {
let (uv, decoded_bytes) = Self::try_decode_var_u64(buf)?;
let v = uv >> 1;
if unsafe { likely(uv & 1 == 0) } {
if uv & 1 == 0 {
// no need for likely/unlikely here
Ok((v as i64, decoded_bytes))
} else {
Ok((!v as i64, decoded_bytes))
Expand Down Expand Up @@ -515,7 +516,7 @@ impl NumberCodec {
while ptr != ptr_end && *ptr >= 0x80 {
ptr = ptr.add(1);
}
// We we got here, we are either `ptr == ptr_end`, or `*ptr < 0x80`.
// When we got here, we are either `ptr == ptr_end`, or `*ptr < 0x80`.
// For `ptr == ptr_end` case, it means we are expecting a value < 0x80
// but meet EOF, so only `len` is returned.
// For `*ptr < 0x80` case, it means currently it is pointing to the last byte
Expand Down

0 comments on commit 3c1bbd1

Please sign in to comment.