mirror of
https://github.com/tokio-rs/bytes.git
synced 2026-08-29 00:00:15 +02:00
Address various clippy warnings (#528)
This commit is contained in:
+1
-1
@@ -46,7 +46,7 @@ impl TestBuf {
|
|||||||
}
|
}
|
||||||
impl Buf for TestBuf {
|
impl Buf for TestBuf {
|
||||||
fn remaining(&self) -> usize {
|
fn remaining(&self) -> usize {
|
||||||
return self.buf.len() - self.pos;
|
self.buf.len() - self.pos
|
||||||
}
|
}
|
||||||
fn advance(&mut self, cnt: usize) {
|
fn advance(&mut self, cnt: usize) {
|
||||||
self.pos += cnt;
|
self.pos += cnt;
|
||||||
|
|||||||
@@ -88,6 +88,7 @@ fn from_long_slice(b: &mut Bencher) {
|
|||||||
#[bench]
|
#[bench]
|
||||||
fn slice_empty(b: &mut Bencher) {
|
fn slice_empty(b: &mut Bencher) {
|
||||||
b.iter(|| {
|
b.iter(|| {
|
||||||
|
// `clone` is to convert to ARC
|
||||||
let b = Bytes::from(vec![17; 1024]).clone();
|
let b = Bytes::from(vec![17; 1024]).clone();
|
||||||
for i in 0..1000 {
|
for i in 0..1000 {
|
||||||
test::black_box(b.slice(i % 100..i % 100));
|
test::black_box(b.slice(i % 100..i % 100));
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
msrv = "1.39"
|
||||||
+5
-5
@@ -262,7 +262,7 @@ impl Bytes {
|
|||||||
let mut ret = self.clone();
|
let mut ret = self.clone();
|
||||||
|
|
||||||
ret.len = end - begin;
|
ret.len = end - begin;
|
||||||
ret.ptr = unsafe { ret.ptr.offset(begin as isize) };
|
ret.ptr = unsafe { ret.ptr.add(begin) };
|
||||||
|
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
@@ -501,7 +501,7 @@ impl Bytes {
|
|||||||
// should already be asserted, but debug assert for tests
|
// should already be asserted, but debug assert for tests
|
||||||
debug_assert!(self.len >= by, "internal: inc_start out of bounds");
|
debug_assert!(self.len >= by, "internal: inc_start out of bounds");
|
||||||
self.len -= by;
|
self.len -= by;
|
||||||
self.ptr = self.ptr.offset(by as isize);
|
self.ptr = self.ptr.add(by);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -604,7 +604,7 @@ impl<'a> IntoIterator for &'a Bytes {
|
|||||||
type IntoIter = core::slice::Iter<'a, u8>;
|
type IntoIter = core::slice::Iter<'a, u8>;
|
||||||
|
|
||||||
fn into_iter(self) -> Self::IntoIter {
|
fn into_iter(self) -> Self::IntoIter {
|
||||||
self.as_slice().into_iter()
|
self.as_slice().iter()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -686,7 +686,7 @@ impl PartialOrd<Bytes> for str {
|
|||||||
|
|
||||||
impl PartialEq<Vec<u8>> for Bytes {
|
impl PartialEq<Vec<u8>> for Bytes {
|
||||||
fn eq(&self, other: &Vec<u8>) -> bool {
|
fn eq(&self, other: &Vec<u8>) -> bool {
|
||||||
*self == &other[..]
|
*self == other[..]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -710,7 +710,7 @@ impl PartialOrd<Bytes> for Vec<u8> {
|
|||||||
|
|
||||||
impl PartialEq<String> for Bytes {
|
impl PartialEq<String> for Bytes {
|
||||||
fn eq(&self, other: &String) -> bool {
|
fn eq(&self, other: &String) -> bool {
|
||||||
*self == &other[..]
|
*self == other[..]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+11
-11
@@ -603,7 +603,7 @@ impl BytesMut {
|
|||||||
v.reserve(additional);
|
v.reserve(additional);
|
||||||
|
|
||||||
// Update the info
|
// Update the info
|
||||||
self.ptr = vptr(v.as_mut_ptr().offset(off as isize));
|
self.ptr = vptr(v.as_mut_ptr().add(off));
|
||||||
self.len = v.len() - off;
|
self.len = v.len() - off;
|
||||||
self.cap = v.capacity() - off;
|
self.cap = v.capacity() - off;
|
||||||
}
|
}
|
||||||
@@ -818,7 +818,7 @@ impl BytesMut {
|
|||||||
// Updating the start of the view is setting `ptr` to point to the
|
// Updating the start of the view is setting `ptr` to point to the
|
||||||
// new start and updating the `len` field to reflect the new length
|
// new start and updating the `len` field to reflect the new length
|
||||||
// of the view.
|
// of the view.
|
||||||
self.ptr = vptr(self.ptr.as_ptr().offset(start as isize));
|
self.ptr = vptr(self.ptr.as_ptr().add(start));
|
||||||
|
|
||||||
if self.len >= start {
|
if self.len >= start {
|
||||||
self.len -= start;
|
self.len -= start;
|
||||||
@@ -842,7 +842,7 @@ impl BytesMut {
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
let ptr = unsafe { self.ptr.as_ptr().offset(self.len as isize) };
|
let ptr = unsafe { self.ptr.as_ptr().add(self.len) };
|
||||||
if ptr == other.ptr.as_ptr()
|
if ptr == other.ptr.as_ptr()
|
||||||
&& self.kind() == KIND_ARC
|
&& self.kind() == KIND_ARC
|
||||||
&& other.kind() == KIND_ARC
|
&& other.kind() == KIND_ARC
|
||||||
@@ -931,7 +931,7 @@ impl BytesMut {
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn uninit_slice(&mut self) -> &mut UninitSlice {
|
fn uninit_slice(&mut self) -> &mut UninitSlice {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ptr = self.ptr.as_ptr().offset(self.len as isize);
|
let ptr = self.ptr.as_ptr().add(self.len);
|
||||||
let len = self.cap - self.len;
|
let len = self.cap - self.len;
|
||||||
|
|
||||||
UninitSlice::from_raw_parts_mut(ptr, len)
|
UninitSlice::from_raw_parts_mut(ptr, len)
|
||||||
@@ -1178,7 +1178,7 @@ impl<'a> IntoIterator for &'a BytesMut {
|
|||||||
type IntoIter = core::slice::Iter<'a, u8>;
|
type IntoIter = core::slice::Iter<'a, u8>;
|
||||||
|
|
||||||
fn into_iter(self) -> Self::IntoIter {
|
fn into_iter(self) -> Self::IntoIter {
|
||||||
self.as_ref().into_iter()
|
self.as_ref().iter()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1207,7 +1207,7 @@ impl<'a> Extend<&'a u8> for BytesMut {
|
|||||||
where
|
where
|
||||||
T: IntoIterator<Item = &'a u8>,
|
T: IntoIterator<Item = &'a u8>,
|
||||||
{
|
{
|
||||||
self.extend(iter.into_iter().map(|b| *b))
|
self.extend(iter.into_iter().copied())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1219,7 +1219,7 @@ impl FromIterator<u8> for BytesMut {
|
|||||||
|
|
||||||
impl<'a> FromIterator<&'a u8> for BytesMut {
|
impl<'a> FromIterator<&'a u8> for BytesMut {
|
||||||
fn from_iter<T: IntoIterator<Item = &'a u8>>(into_iter: T) -> Self {
|
fn from_iter<T: IntoIterator<Item = &'a u8>>(into_iter: T) -> Self {
|
||||||
BytesMut::from_iter(into_iter.into_iter().map(|b| *b))
|
BytesMut::from_iter(into_iter.into_iter().copied())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1409,7 +1409,7 @@ impl PartialOrd<BytesMut> for str {
|
|||||||
|
|
||||||
impl PartialEq<Vec<u8>> for BytesMut {
|
impl PartialEq<Vec<u8>> for BytesMut {
|
||||||
fn eq(&self, other: &Vec<u8>) -> bool {
|
fn eq(&self, other: &Vec<u8>) -> bool {
|
||||||
*self == &other[..]
|
*self == other[..]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1433,7 +1433,7 @@ impl PartialOrd<BytesMut> for Vec<u8> {
|
|||||||
|
|
||||||
impl PartialEq<String> for BytesMut {
|
impl PartialEq<String> for BytesMut {
|
||||||
fn eq(&self, other: &String) -> bool {
|
fn eq(&self, other: &String) -> bool {
|
||||||
*self == &other[..]
|
*self == other[..]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1499,13 +1499,13 @@ impl PartialOrd<BytesMut> for &str {
|
|||||||
|
|
||||||
impl PartialEq<BytesMut> for Bytes {
|
impl PartialEq<BytesMut> for Bytes {
|
||||||
fn eq(&self, other: &BytesMut) -> bool {
|
fn eq(&self, other: &BytesMut) -> bool {
|
||||||
&other[..] == &self[..]
|
other[..] == self[..]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PartialEq<Bytes> for BytesMut {
|
impl PartialEq<Bytes> for BytesMut {
|
||||||
fn eq(&self, other: &Bytes) -> bool {
|
fn eq(&self, other: &Bytes) -> bool {
|
||||||
&other[..] == &self[..]
|
other[..] == self[..]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -25,7 +25,7 @@ impl Debug for BytesRef<'_> {
|
|||||||
} else if b == b'\0' {
|
} else if b == b'\0' {
|
||||||
write!(f, "\\0")?;
|
write!(f, "\\0")?;
|
||||||
// ASCII printable
|
// ASCII printable
|
||||||
} else if b >= 0x20 && b < 0x7f {
|
} else if (0x20..0x7f).contains(&b) {
|
||||||
write!(f, "{}", b as char)?;
|
write!(f, "{}", b as char)?;
|
||||||
} else {
|
} else {
|
||||||
write!(f, "\\x{:02x}", b)?;
|
write!(f, "\\x{:02x}", b)?;
|
||||||
@@ -38,12 +38,12 @@ impl Debug for BytesRef<'_> {
|
|||||||
|
|
||||||
impl Debug for Bytes {
|
impl Debug for Bytes {
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
|
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
|
||||||
Debug::fmt(&BytesRef(&self.as_ref()), f)
|
Debug::fmt(&BytesRef(self.as_ref()), f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Debug for BytesMut {
|
impl Debug for BytesMut {
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
|
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
|
||||||
Debug::fmt(&BytesRef(&self.as_ref()), f)
|
Debug::fmt(&BytesRef(self.as_ref()), f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -4,8 +4,8 @@ use bytes::{Buf, BufMut, Bytes, BytesMut};
|
|||||||
|
|
||||||
use std::usize;
|
use std::usize;
|
||||||
|
|
||||||
const LONG: &'static [u8] = b"mary had a little lamb, little lamb, little lamb";
|
const LONG: &[u8] = b"mary had a little lamb, little lamb, little lamb";
|
||||||
const SHORT: &'static [u8] = b"hello world";
|
const SHORT: &[u8] = b"hello world";
|
||||||
|
|
||||||
fn is_sync<T: Sync>() {}
|
fn is_sync<T: Sync>() {}
|
||||||
fn is_send<T: Send>() {}
|
fn is_send<T: Send>() {}
|
||||||
@@ -874,7 +874,7 @@ fn from_iter_no_size_hint() {
|
|||||||
|
|
||||||
fn test_slice_ref(bytes: &Bytes, start: usize, end: usize, expected: &[u8]) {
|
fn test_slice_ref(bytes: &Bytes, start: usize, end: usize, expected: &[u8]) {
|
||||||
let slice = &(bytes.as_ref()[start..end]);
|
let slice = &(bytes.as_ref()[start..end]);
|
||||||
let sub = bytes.slice_ref(&slice);
|
let sub = bytes.slice_ref(slice);
|
||||||
assert_eq!(&sub[..], expected);
|
assert_eq!(&sub[..], expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -894,7 +894,7 @@ fn slice_ref_empty() {
|
|||||||
let bytes = Bytes::from(&b""[..]);
|
let bytes = Bytes::from(&b""[..]);
|
||||||
let slice = &(bytes.as_ref()[0..0]);
|
let slice = &(bytes.as_ref()[0..0]);
|
||||||
|
|
||||||
let sub = bytes.slice_ref(&slice);
|
let sub = bytes.slice_ref(slice);
|
||||||
assert_eq!(&sub[..], b"");
|
assert_eq!(&sub[..], b"");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,8 +24,7 @@ unsafe impl GlobalAlloc for Odd {
|
|||||||
};
|
};
|
||||||
let ptr = System.alloc(new_layout);
|
let ptr = System.alloc(new_layout);
|
||||||
if !ptr.is_null() {
|
if !ptr.is_null() {
|
||||||
let ptr = ptr.offset(1);
|
ptr.offset(1)
|
||||||
ptr
|
|
||||||
} else {
|
} else {
|
||||||
ptr
|
ptr
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user