Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

codec: Some small improvements #4664

Merged
merged 10 commits into from
May 10, 2019
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion components/codec/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ publish = false
[dependencies]
libc = "0.2"
byteorder = "1.2"
quick-error = "1.2"
failure = "0.1"
panic_hook = { path = "../panic_hook" }
tikv_alloc = { path = "../tikv_alloc", default-features = false }

Expand Down
10 changes: 2 additions & 8 deletions components/codec/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ impl<T: AsRef<[u8]>> BufferReader for std::io::Cursor<T> {
fn bytes(&self) -> &[u8] {
let pos = self.position() as usize;
let slice = self.get_ref().as_ref();
if pos >= slice.len() {
return &[];
}
&slice[pos..]
slice.get(pos..).unwrap_or(&[])
}

fn advance(&mut self, count: usize) {
Expand Down Expand Up @@ -103,10 +100,7 @@ impl<T: AsMut<[u8]>> BufferWriter for std::io::Cursor<T> {
// `size` is ignored since this buffer is not capable to grow.
let pos = self.position() as usize;
let slice = self.get_mut().as_mut();
if pos >= slice.len() {
return &mut [];
}
&mut slice[pos..]
slice.get_mut(pos..).unwrap_or(&mut [])
}

unsafe fn advance_mut(&mut self, count: usize) {
Expand Down
Loading