Skip to content

Commit d2df613

Browse files
authored
Merge pull request #256 from Pivot-Studio/refactor/clippy
refactor:fix clippy
2 parents 943f7a1 + bb452d9 commit d2df613

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+862
-923
lines changed

.github/workflows/test.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,6 @@ jobs:
170170

171171
- name: Run cargo clippy
172172
uses: actions-rs/clippy-check@v1
173-
env:
174-
RUSTFLAGS: ""
175173
with:
176174
token: ${{ secrets.GITHUB_TOKEN }}
177175
args: --all-features

immix/src/allocator/big_obj_allocator.rs

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -56,24 +56,28 @@ impl BigObjAllocator {
5656
for i in 0..self.unused_chunks.len() {
5757
let unused_obj = self.unused_chunks[i];
5858
let unused_size = unsafe { (*unused_obj).size };
59-
if unused_size == size {
60-
self.unused_chunks.remove(i);
61-
// self.mmap.commit(unused_obj as *mut u8, size);
62-
println!(
63-
"get_chunk: {:p}[reused {}/{}]",
64-
unused_obj, size, unused_size
65-
);
66-
return unused_obj;
67-
} else if unused_size > size {
68-
let ptr = unsafe { (unused_obj as *mut u8).add(unused_size - size) };
69-
let new_obj = BigObj::new(ptr, size);
70-
unsafe {
71-
(*unused_obj).size -= size;
59+
match unused_size.cmp(&size) {
60+
std::cmp::Ordering::Less => {}
61+
std::cmp::Ordering::Equal => {
62+
self.unused_chunks.remove(i);
63+
// self.mmap.commit(unused_obj as *mut u8, size);
64+
println!(
65+
"get_chunk: {:p}[reused {}/{}]",
66+
unused_obj, size, unused_size
67+
);
68+
return unused_obj;
7269
}
73-
// self.mmap.commit(new_obj as *mut BigObj as *mut u8, size);
74-
println!("get_chunk: {:p}[reused {}/{}]", new_obj, size, unused_size);
75-
return new_obj;
76-
}
70+
std::cmp::Ordering::Greater => {
71+
let ptr = unsafe { (unused_obj as *mut u8).add(unused_size - size) };
72+
let new_obj = BigObj::new(ptr, size);
73+
unsafe {
74+
(*unused_obj).size -= size;
75+
}
76+
// self.mmap.commit(new_obj as *mut BigObj as *mut u8, size);
77+
println!("get_chunk: {:p}[reused {}/{}]", new_obj, size, unused_size);
78+
return new_obj;
79+
}
80+
};
7781
}
7882

7983
let chunk = self.alloc_chunk(size).unwrap();

immix/src/allocator/thread_local_allocator.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,10 @@ impl ThreadLocalAllocator {
223223
let uf = self.recyclable_blocks.pop_front().unwrap();
224224
self.unavailable_blocks.push(uf);
225225
let ff = self.recyclable_blocks.front();
226-
if ff.is_none() {
227-
// recycle blocks全用光了
228-
return self.alloc(size, obj_type);
226+
if let Some(ff) = ff {
227+
f = ff;
229228
} else {
230-
f = ff.unwrap()
229+
return self.alloc(size, obj_type);
231230
}
232231
}
233232
}

immix/src/block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ impl Block {
233233
// 未使用或者未标记
234234
if !self.line_map[idx].get_used()
235235
|| (self.line_map[idx] & 0b10 == 0 //即使标记位为0,也有可能是被标记的对象数据体
236-
&& (!marked || (marked && self.line_map[idx] & 0b10000010 == 0b10000000)))
236+
&& (!marked || self.line_map[idx] & 0b10000010 == 0b10000000))
237237
{
238238
len += 1;
239239
self.line_map[idx] &= 0;

immix/src/collector.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ impl Collector {
176176
.as_mut()
177177
.unwrap()
178178
.alloc(size, obj_type);
179-
debug_assert!(ptr.is_null() == false);
179+
debug_assert!(!ptr.is_null());
180180
ptr
181181
}
182182
}

pl_linker/src/linker.rs

Lines changed: 35 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -226,13 +226,7 @@ impl Linker for Ld64Linker {
226226
// use ld for default linker, as lld has a bug affcting backtrace on arm64 target
227227
// https://github.com/rust-lang/backtrace-rs/issues/150
228228
let re = Command::new("ld").args(&self.args).output();
229-
if re.is_err() {
230-
println!("ld not found, try to link with lld, this may break gc(https://github.com/rust-lang/backtrace-rs/issues/150)");
231-
lld_rs::link(lld_rs::LldFlavor::MachO, &self.args)
232-
.ok()
233-
.map_err(LinkerError::LinkError)
234-
} else {
235-
let re = re.unwrap();
229+
if let Ok(re) = re {
236230
if !re.status.success() {
237231
eprintln!(
238232
"link failed\nargs: {:?}\nld stdout: {}, stderr: {}",
@@ -244,6 +238,11 @@ impl Linker for Ld64Linker {
244238
} else {
245239
Ok(())
246240
}
241+
} else {
242+
println!("ld not found, try to link with lld, this may break gc(https://github.com/rust-lang/backtrace-rs/issues/150)");
243+
lld_rs::link(lld_rs::LldFlavor::MachO, &self.args)
244+
.ok()
245+
.map_err(LinkerError::LinkError)
247246
}
248247
} else {
249248
lld_rs::link(lld_rs::LldFlavor::MachO, &self.args)
@@ -319,14 +318,7 @@ impl Linker for MsvcLinker {
319318
let re = Command::new(linker.expect("failed to find link.exe"))
320319
.args(&self.args)
321320
.output();
322-
323-
if re.is_err() {
324-
return Err(LinkerError::LinkError(format!(
325-
"link failed: {:?}",
326-
re.err()
327-
)));
328-
} else {
329-
let re = re.unwrap();
321+
if let Ok(re) = re {
330322
if !re.status.success() {
331323
eprintln!(
332324
"link failed\nargs: {:?}\nld stdout: {}, stderr: {}",
@@ -338,6 +330,11 @@ impl Linker for MsvcLinker {
338330
} else {
339331
Ok(())
340332
}
333+
} else {
334+
Err(LinkerError::LinkError(format!(
335+
"link failed: {:?}",
336+
re.err()
337+
)))
341338
}
342339
}
343340

@@ -388,33 +385,29 @@ fn get_win_sdk_lib_paths() -> (Option<PathBuf>, Vec<PathBuf>) {
388385
});
389386
let sdkroot = PathBuf::from(r"C:\Program Files (x86)\Windows Kits\");
390387
assert!(sdkroot.is_dir(), "Windows SDK not found");
391-
for dir in sdkroot.read_dir().unwrap() {
392-
if let Ok(dir) = dir {
393-
if dir.path().is_symlink() || !dir.path().is_dir() {
394-
continue;
395-
}
396-
let mut p = dir.path();
397-
p.push("Lib");
398-
if p.is_dir() {
399-
for d in p.read_dir().unwrap() {
400-
if let Ok(d) = d {
401-
if d.path().is_dir() {
402-
let mut p = d.path();
403-
p.push("ucrt\\x64");
404-
if p.exists() {
405-
paths.push(p);
406-
}
407-
let mut p = d.path();
408-
p.push("um\\x64");
409-
if p.exists() {
410-
paths.push(p);
411-
}
412-
if paths.len() == 4 {
413-
return (linker_path, paths);
414-
} else {
415-
paths = paths[0..2].to_vec();
416-
}
417-
}
388+
for dir in sdkroot.read_dir().unwrap().flatten() {
389+
if dir.path().is_symlink() || !dir.path().is_dir() {
390+
continue;
391+
}
392+
let mut p = dir.path();
393+
p.push("Lib");
394+
if p.is_dir() {
395+
for d in p.read_dir().unwrap().flatten() {
396+
if d.path().is_dir() {
397+
let mut p = d.path();
398+
p.push("ucrt\\x64");
399+
if p.exists() {
400+
paths.push(p);
401+
}
402+
let mut p = d.path();
403+
p.push("um\\x64");
404+
if p.exists() {
405+
paths.push(p);
406+
}
407+
if paths.len() == 4 {
408+
return (linker_path, paths);
409+
} else {
410+
paths = paths[0..2].to_vec();
418411
}
419412
}
420413
}

0 commit comments

Comments
 (0)