libs: Fix clippy len_zero

Fix `len_zero` clippy warning as suggested by rust 1.85.1, since
`mem-agent` is now a member of `libs` workspace.

```console
error: length comparison to zero
   --> mem-agent/src/memcg.rs:225:61
    |
225 |             let (keep, moved) = vec.drain(..).partition(|c| c.numa_id.len() > 0);
    |                                                             ^^^^^^^^^^^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!c.numa_id.is_empty()`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#len_zero
```

Signed-off-by: Ruoqing He <heruoqing@iscas.ac.cn>
This commit is contained in:
Ruoqing He
2025-08-26 08:25:38 +00:00
parent 1a0935d35c
commit 150aee088d
3 changed files with 11 additions and 11 deletions

View File

@@ -105,7 +105,7 @@ async fn async_get_remaining_tokio_duration(
fn agent_work(mut memcg: memcg::MemCG, mut comp: compact::Compact) -> Result<Duration> {
let memcg_work_list = memcg.get_timeout_list();
if memcg_work_list.len() > 0 {
if !memcg_work_list.is_empty() {
info!("memcg.work start");
memcg
.work(&memcg_work_list)

View File

@@ -222,7 +222,7 @@ impl Config {
// make sure the empty numa_id CgroupConfig at the end of Cgroup
for vec in self.cgroups.values_mut() {
let (keep, moved) = vec.drain(..).partition(|c| c.numa_id.len() > 0);
let (keep, moved) = vec.drain(..).partition(|c| !c.numa_id.is_empty());
*vec = keep;
vec.extend(moved);
}
@@ -534,9 +534,9 @@ impl MemCgroups {
}
should_keep
});
path_cgs.len() != 0
!path_cgs.is_empty()
});
period_cgs.cgs.len() != 0
!period_cgs.cgs.is_empty()
});
self.cgroups.retain(|path, cgroup| {
@@ -718,7 +718,7 @@ impl MemCgroups {
}
}
if info_ret.len() > 0 {
if !info_ret.is_empty() {
infos_ret.push((single_config.clone(), info_ret));
}
}
@@ -1024,7 +1024,7 @@ impl MemCG {
let mut mgs = self.memcgs.blocking_write();
if target_paths.len() == 0 {
if target_paths.is_empty() {
mgs.remove_changed(&mg_hash);
}
mgs.update_and_add(&mg_hash, true);
@@ -1135,7 +1135,7 @@ impl MemCG {
let mut ret = Ok(());
'main_loop: while infov.len() != 0 {
'main_loop: while !infov.is_empty() {
// update infov
let path_set: HashSet<String> = infov.iter().map(|info| info.path.clone()).collect();
match self.refresh(&path_set) {
@@ -1373,6 +1373,6 @@ mod tests {
fn test_memcg_get_timeout_list() {
let is_cg_v2 = crate::cgroup::is_cgroup_v2().unwrap();
let m = MemCG::new(is_cg_v2, Config::default()).unwrap();
assert!(m.get_timeout_list().len() > 0);
assert!(!m.get_timeout_list().is_empty());
}
}

View File

@@ -77,7 +77,7 @@ impl MGenLRU {
fn lru_gen_lines_parse(reader: &mut BufReader<File>) -> Result<(String, HashMap<usize, MGenLRU>)> {
let mut line = String::new();
let mut ret_hash = HashMap::new();
while line.len() > 0
while !line.is_empty()
|| reader
.read_line(&mut line)
.map_err(|e| anyhow!("read file {} failed: {}", LRU_GEN_PATH, e))?
@@ -180,7 +180,7 @@ fn lru_gen_file_parse(
) -> Result<HashMap<String, (usize, HashMap<usize, MGenLRU>)>> {
let mut line = String::new();
let mut ret_hash = HashMap::new();
while line.len() > 0
while !line.is_empty()
|| reader
.read_line(&mut line)
.map_err(|e| anyhow!("read file {} failed: {}", LRU_GEN_PATH, e))?
@@ -189,7 +189,7 @@ fn lru_gen_file_parse(
let mut clear_line = true;
// Not handle the Err of lru_gen_head_parse because all lines of file will be checked.
if let Ok((id, path)) = lru_gen_head_parse(&line) {
if target_patchs.len() == 0 || target_patchs.contains(&path) {
if target_patchs.is_empty() || target_patchs.contains(&path) {
let seq_data = if parse_line {
let (ret_line, data) = lru_gen_lines_parse(&mut reader).map_err(|e| {
anyhow!(