simplify some logic (#9777)

* simplify some logic

* simplify a &*
This commit is contained in:
AsukaMinato 2023-05-07 22:39:34 +09:00 committed by GitHub
parent 6a301381c8
commit e2fdc63cdb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1419,20 +1419,11 @@ pub fn read_blocked(fd: RawFd, buf: &mut [u8]) -> isize {
/// Test if the string is a valid function name.
pub fn valid_func_name(name: &wstr) -> bool {
if name.is_empty() {
return false;
};
if name.char_at(0) == '-' {
return false;
};
!(name.is_empty()
|| name.starts_with('-')
// A function name needs to be a valid path, so no / and no NULL.
if name.find_char('/').is_some() {
return false;
};
if name.find_char('\0').is_some() {
return false;
};
true
|| name.contains('/')
|| name.contains('\0'))
}
/// A rusty port of the C++ `write_loop()` function from `common.cpp`. This should be deprecated in
@ -1720,7 +1711,7 @@ fn get_executable_path(argv0: &str) -> PathBuf {
/// the replacement value. Useful to avoid errors about multiple references (`&mut T` for `old` then
/// `&T` again in the `new` expression).
pub fn replace_with<T, F: FnOnce(&T) -> T>(old: &mut T, with: F) -> T {
let new = with(&*old);
let new = with(old);
std::mem::replace(old, new)
}