mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2025-01-27 02:28:22 +00:00
clippy: Disallow len_without_is_empty and len_zero
BUG=b:283512997 TEST=none Change-Id: I0477583b3f8c8eefeb1d79f11302b1b28a8bd770 Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4549999 Reviewed-by: Dennis Kempin <denniskempin@google.com> Commit-Queue: Vikram Auradkar <auradkar@google.com>
This commit is contained in:
parent
bc604656c9
commit
f054575a8b
24 changed files with 61 additions and 23 deletions
|
@ -14,8 +14,6 @@ rustflags = [
|
|||
"-Aclippy::collapsible_if",
|
||||
"-Aclippy::enum_variant_names",
|
||||
"-Aclippy::identity_op",
|
||||
"-Aclippy::len_without_is_empty",
|
||||
"-Aclippy::len_zero",
|
||||
"-Aclippy::match_bool",
|
||||
"-Aclippy::match_wild_err_arm",
|
||||
"-Aclippy::needless_bool",
|
||||
|
|
|
@ -86,6 +86,11 @@ impl<'a> IoBufMut<'a> {
|
|||
self.buf.len as usize
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.buf.len == 0
|
||||
}
|
||||
|
||||
/// Gets a const pointer to this slice's memory.
|
||||
#[inline]
|
||||
pub fn as_ptr(&self) -> *const u8 {
|
||||
|
|
|
@ -94,6 +94,10 @@ impl VecIoWrapper {
|
|||
self.inner.len()
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.len() == 0
|
||||
}
|
||||
|
||||
// Check that the offsets are all valid in the backing vec.
|
||||
fn check_addrs(&self, mem_range: &MemRegion) -> Result<()> {
|
||||
let end = mem_range
|
||||
|
|
|
@ -191,7 +191,7 @@ impl BusStatistics {
|
|||
|
||||
/// Merge several BusStatistics into one.
|
||||
pub fn merged(stats: &[Arc<Mutex<BusStatistics>>]) -> BusStatistics {
|
||||
if stats.len() == 0 {
|
||||
if stats.is_empty() {
|
||||
return BusStatistics::new();
|
||||
}
|
||||
|
||||
|
|
|
@ -70,6 +70,10 @@ impl ScatterGatherBuffer {
|
|||
Ok(total_len)
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> Result<bool> {
|
||||
Ok(self.len()? == 0)
|
||||
}
|
||||
|
||||
/// Get the guest address and length of the TRB's data buffer.
|
||||
/// This is usually a separate buffer pointed to by the TRB,
|
||||
/// but it can also be within the TRB itself in the case of immediate data.
|
||||
|
|
|
@ -257,6 +257,11 @@ impl BasicMemoryMapper {
|
|||
pub fn len(&self) -> usize {
|
||||
self.maps.len()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.maps.is_empty()
|
||||
}
|
||||
}
|
||||
|
||||
impl MemoryMapper for BasicMemoryMapper {
|
||||
|
|
|
@ -304,7 +304,7 @@ impl Stream {
|
|||
}
|
||||
StreamState::Prepared => {} // Do nothing, any buffers will be processed after start
|
||||
_ => {
|
||||
if self.buffer_queue.len() > 0 {
|
||||
if !self.buffer_queue.is_empty() {
|
||||
warn!("virtio-snd: Buffers received while in unexpected state");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -104,7 +104,7 @@ impl VfioReceiver {
|
|||
.context("failed to receive data")
|
||||
.map_err(RecvIntoBufsError::Fatal)?;
|
||||
|
||||
if data.len() == 0 {
|
||||
if data.is_empty() {
|
||||
// TODO(b/216407443): We should change `self.state` and exit gracefully.
|
||||
info!("VVU connection is closed");
|
||||
return Err(RecvIntoBufsError::Disconnect);
|
||||
|
|
|
@ -82,6 +82,10 @@ impl AvBufferSource for InputBuffer {
|
|||
fn len(&self) -> usize {
|
||||
self.mapping.size()
|
||||
}
|
||||
|
||||
fn is_empty(&self) -> bool {
|
||||
self.len() == 0
|
||||
}
|
||||
}
|
||||
|
||||
/// Types of input job we can receive from the crosvm decoder code.
|
||||
|
|
|
@ -84,6 +84,10 @@ impl AvBufferSource for InputBuffer {
|
|||
fn len(&self) -> usize {
|
||||
self.mapping.size()
|
||||
}
|
||||
|
||||
fn is_empty(&self) -> bool {
|
||||
self.len() == 0
|
||||
}
|
||||
}
|
||||
|
||||
enum CodecJob {
|
||||
|
|
|
@ -62,7 +62,7 @@ impl LibvdaEncoder {
|
|||
output_formats,
|
||||
} = instance.get_capabilities();
|
||||
|
||||
if input_formats.len() == 0 || output_formats.len() == 0 {
|
||||
if input_formats.is_empty() || output_formats.is_empty() {
|
||||
error!("No input or output formats.");
|
||||
return Err(VideoError::InvalidFormat);
|
||||
}
|
||||
|
|
|
@ -328,7 +328,7 @@ impl<T: EncoderSession> Stream<T> {
|
|||
));
|
||||
}
|
||||
|
||||
if responses.len() > 0 {
|
||||
if !responses.is_empty() {
|
||||
Some(responses)
|
||||
} else {
|
||||
None
|
||||
|
@ -783,7 +783,7 @@ impl<T: Encoder> EncoderDevice<T> {
|
|||
// We currently only support single-buffer formats, but some clients may mistake
|
||||
// color planes with memory planes and submit several planes to us. This doesn't
|
||||
// matter as we will only consider the first one.
|
||||
if data_sizes.len() < 1 {
|
||||
if data_sizes.is_empty() {
|
||||
return Err(VideoError::InvalidParameter);
|
||||
}
|
||||
|
||||
|
@ -1035,8 +1035,8 @@ impl<T: Encoder> EncoderDevice<T> {
|
|||
let mut create_session = stream.encoder_session.is_none();
|
||||
// TODO(ishitatsuyuki): We should additionally check that no resources are *attached* while
|
||||
// a params is being set.
|
||||
let src_resources_queued = stream.src_resources.len() > 0;
|
||||
let dst_resources_queued = stream.dst_resources.len() > 0;
|
||||
let src_resources_queued = !stream.src_resources.is_empty();
|
||||
let dst_resources_queued = !stream.dst_resources.is_empty();
|
||||
|
||||
// Dynamic framerate changes are allowed. The framerate can be set on either the input or
|
||||
// output queue. Changing the framerate can influence the selected H.264 level, as the
|
||||
|
@ -1273,7 +1273,7 @@ impl<T: Encoder> EncoderDevice<T> {
|
|||
.get_mut(&stream_id)
|
||||
.ok_or(VideoError::InvalidStreamId(stream_id))?;
|
||||
let mut recreate_session = false;
|
||||
let resources_queued = stream.src_resources.len() > 0 || stream.dst_resources.len() > 0;
|
||||
let resources_queued = !stream.src_resources.is_empty() || !stream.dst_resources.is_empty();
|
||||
|
||||
match ctrl_val {
|
||||
CtrlVal::BitrateMode(bitrate_mode) => {
|
||||
|
|
|
@ -45,6 +45,10 @@ impl AvBufferSource for MemoryMappingAvBufferSource {
|
|||
fn len(&self) -> usize {
|
||||
self.0.size()
|
||||
}
|
||||
|
||||
fn is_empty(&self) -> bool {
|
||||
self.len() == 0
|
||||
}
|
||||
}
|
||||
|
||||
pub trait TryAsAvFrameExt {
|
||||
|
@ -156,7 +160,7 @@ impl TryFrom<Format> for AvPixelFormat {
|
|||
})
|
||||
.map_err(|_|
|
||||
// The error case should never happen as long as we use valid constant values, but
|
||||
// don't panic in case something goes wrong.
|
||||
// don't panic in case something goes wrong.
|
||||
TryFromFormatError(()))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ impl<T> EventQueue<T> {
|
|||
|
||||
/// Remove all the posted events for which `predicate` returns `false`.
|
||||
pub fn retain<P: FnMut(&T) -> bool>(&mut self, predicate: P) {
|
||||
if self.pending_events.len() > 0 {
|
||||
if !self.pending_events.is_empty() {
|
||||
let _ = self
|
||||
.event
|
||||
.wait_timeout(Duration::from_millis(0))
|
||||
|
|
|
@ -958,4 +958,9 @@ impl Xsave {
|
|||
pub fn len(&self) -> usize {
|
||||
self.len
|
||||
}
|
||||
|
||||
/// Returns true is length of XSAVE data is zero
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.len() == 0
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,14 +39,14 @@ use vm_memory::GuestMemory;
|
|||
fn get_supported_cpuid() {
|
||||
let hypervisor = Kvm::new().unwrap();
|
||||
let cpuid = hypervisor.get_supported_cpuid().unwrap();
|
||||
assert!(cpuid.cpu_id_entries.len() > 0);
|
||||
assert!(!cpuid.cpu_id_entries.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn get_emulated_cpuid() {
|
||||
let hypervisor = Kvm::new().unwrap();
|
||||
let cpuid = hypervisor.get_emulated_cpuid().unwrap();
|
||||
assert!(cpuid.cpu_id_entries.len() > 0);
|
||||
assert!(!cpuid.cpu_id_entries.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -88,7 +88,7 @@ fn get_supported_cpuid() {
|
|||
let kvm = Kvm::new().unwrap();
|
||||
let mut cpuid = kvm.get_supported_cpuid().unwrap();
|
||||
let cpuid_entries = cpuid.mut_entries_slice();
|
||||
assert!(cpuid_entries.len() > 0);
|
||||
assert!(!cpuid_entries.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -584,6 +584,7 @@ pub trait AvBufferSource: Send {
|
|||
self.as_ptr() as *mut u8
|
||||
}
|
||||
fn len(&self) -> usize;
|
||||
fn is_empty(&self) -> bool;
|
||||
}
|
||||
|
||||
/// Wrapper around `AVBuffer` and `AVBufferRef`.
|
||||
|
@ -1023,6 +1024,10 @@ mod tests {
|
|||
fn len(&self) -> usize {
|
||||
0
|
||||
}
|
||||
|
||||
fn is_empty(&self) -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
let dropped = Arc::new(AtomicBool::new(false));
|
||||
|
|
|
@ -300,7 +300,7 @@ impl CrossDomainWorker {
|
|||
match event.token {
|
||||
CrossDomainToken::ContextChannel => {
|
||||
let (len, files) = self.state.receive_msg(receive_buf)?;
|
||||
if len != 0 || files.len() != 0 {
|
||||
if len != 0 || !files.is_empty() {
|
||||
let mut cmd_receive: CrossDomainSendReceive = Default::default();
|
||||
|
||||
let num_files = files.len();
|
||||
|
|
|
@ -625,7 +625,7 @@ impl RutabagaComponent for Gfxstream {
|
|||
fence_handler: RutabagaFenceHandler,
|
||||
) -> RutabagaResult<Box<dyn RutabagaContext>> {
|
||||
let mut name: &str = "gpu_renderer";
|
||||
if let Some(name_string) = context_name.filter(|s| s.len() > 0) {
|
||||
if let Some(name_string) = context_name.filter(|s| !s.is_empty()) {
|
||||
name = name_string;
|
||||
}
|
||||
|
||||
|
|
|
@ -692,7 +692,7 @@ impl RutabagaComponent for VirglRenderer {
|
|||
_fence_handler: RutabagaFenceHandler,
|
||||
) -> RutabagaResult<Box<dyn RutabagaContext>> {
|
||||
let mut name: &str = "gpu_renderer";
|
||||
if let Some(name_string) = context_name.filter(|s| s.len() > 0) {
|
||||
if let Some(name_string) = context_name.filter(|s| !s.is_empty()) {
|
||||
name = name_string;
|
||||
}
|
||||
|
||||
|
|
|
@ -494,7 +494,7 @@ pub fn run_config(cfg: Config) -> Result<()> {
|
|||
config.bind_mounts = true;
|
||||
let uid_map = format!("0 {} 1", geteuid());
|
||||
let gid_map = format!("0 {} 1", getegid());
|
||||
let gid_map = if cfg.plugin_gid_maps.len() > 0 {
|
||||
let gid_map = if !cfg.plugin_gid_maps.is_empty() {
|
||||
gid_map
|
||||
+ &cfg
|
||||
.plugin_gid_maps
|
||||
|
|
|
@ -883,7 +883,7 @@ impl Supervisor {
|
|||
}
|
||||
|
||||
fn all_non_metrics_processes_exited(&self) -> bool {
|
||||
self.children.len() == 0 || self.is_only_metrics_process_running()
|
||||
self.children.is_empty() || self.is_only_metrics_process_running()
|
||||
}
|
||||
|
||||
fn start_exit_timer(&mut self, timeout_token: Token) -> Result<()> {
|
||||
|
@ -1033,7 +1033,7 @@ impl Supervisor {
|
|||
);
|
||||
}
|
||||
ensure_exit_code!(
|
||||
self.children.len() == 0,
|
||||
self.children.is_empty(),
|
||||
Exit::BrokerMetricsExitedTimeout,
|
||||
"metrics exited, but other broker children did not exit within the \
|
||||
timeout",
|
||||
|
|
|
@ -171,7 +171,7 @@ static SHOULD_PREPARE_MEMORY_REGION: Lazy<bool> = Lazy::new(|| {
|
|||
// so avoid mapping the whole shared memory region if we're not
|
||||
// using the tdp mmu.
|
||||
match std::fs::read("/sys/module/kvm/parameters/tdp_mmu") {
|
||||
Ok(bytes) if bytes.len() > 0 => bytes[0] == b'Y',
|
||||
Ok(bytes) if !bytes.is_empty() => bytes[0] == b'Y',
|
||||
_ => false,
|
||||
}
|
||||
} else if cfg!(target_pointer_width = "64") {
|
||||
|
|
Loading…
Reference in a new issue