Skip to content

Commit

Permalink
Pass Family by value, not by reference
Browse files Browse the repository at this point in the history
Clippy says: this argument (4 byte) is passed by reference, but would be
more efficient if passed by value (limit: 8 byte)

Signed-off-by: Uli Schlachter <psychon@znc.in>
  • Loading branch information
psychon committed Feb 22, 2020
1 parent 31540f0 commit 1e6289f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/rust_connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl RustConnection<stream::Stream> {
let screen = parsed_display.screen.into();

let (family, address) = stream.peer_addr()?;
let (auth_name, auth_data) = xauth::get_auth(&family, &address, parsed_display.display)
let (auth_name, auth_data) = xauth::get_auth(family, &address, parsed_display.display)
// Ignore all errors while determining auth; instead we just try without auth info.
.unwrap_or(None)
.unwrap_or_else(|| (Vec::new(), Vec::new()));
Expand Down
16 changes: 8 additions & 8 deletions src/rust_connection/xauth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,16 +238,16 @@ pub(crate) type AuthInfo = (Vec<u8>, Vec<u8>);
///
/// If successful, this function returns that can be written to the X11 server as authorization
/// protocol name and data, respectively.
pub(crate) fn get_auth(family: &Family, address: &[u8], display: u16) -> Result<Option<AuthInfo>, Error> {
pub(crate) fn get_auth(family: Family, address: &[u8], display: u16) -> Result<Option<AuthInfo>, Error> {
match file::XAuthorityEntries::new()? {
None => Ok(None),
Some(entries) => get_auth_impl(entries, family, address, display),
}
}

pub(crate) fn get_auth_impl(entries: impl Iterator<Item=Result<AuthEntry, Error>>, family: &Family, address: &[u8], display: u16) -> Result<Option<AuthInfo>, Error> {
fn address_matches((family1, address1): (&Family, &[u8]), (family2, address2): (&Family, &[u8])) -> bool {
if *family1 == Family::Wild || *family2 == Family::Wild {
pub(crate) fn get_auth_impl(entries: impl Iterator<Item=Result<AuthEntry, Error>>, family: Family, address: &[u8], display: u16) -> Result<Option<AuthInfo>, Error> {
fn address_matches((family1, address1): (Family, &[u8]), (family2, address2): (Family, &[u8])) -> bool {
if family1 == Family::Wild || family2 == Family::Wild {
true
} else if family1 != family2 {
false
Expand All @@ -267,7 +267,7 @@ pub(crate) fn get_auth_impl(entries: impl Iterator<Item=Result<AuthEntry, Error>
for entry in entries {
let entry = entry?;

if address_matches((family, address), (&entry.family, &entry.address)) &&
if address_matches((family, address), (entry.family, &entry.address)) &&
display_number_matches(&entry.number, &display[..]) &&
entry.name == MIT_MAGIC_COOKIE_1 {
return Ok(Some((entry.name, entry.data)));
Expand All @@ -292,7 +292,7 @@ mod test {
};
f(&mut entry);
let entries = vec![Ok(entry)];
assert_eq!(get_auth_impl(entries.into_iter(), &Family::Local, b"whatever", 42).unwrap().unwrap(),
assert_eq!(get_auth_impl(entries.into_iter(), Family::Local, b"whatever", 42).unwrap().unwrap(),
(MIT_MAGIC_COOKIE_1.to_vec(), b"1234".to_vec()));
}

Expand All @@ -308,7 +308,7 @@ mod test {
};
f(&mut entry);
let entries = vec![Ok(entry)];
assert_eq!(get_auth_impl(entries.into_iter(), &Family::Local, b"whatever", 42).unwrap(), None);
assert_eq!(get_auth_impl(entries.into_iter(), Family::Local, b"whatever", 42).unwrap(), None);
}

#[test]
Expand Down Expand Up @@ -337,7 +337,7 @@ mod test {
data: b"1234".to_vec(),
};
let entries = vec![Ok(entry)];
assert_eq!(get_auth_impl(entries.into_iter(), &Family::Wild, &[], 42).unwrap().unwrap(),
assert_eq!(get_auth_impl(entries.into_iter(), Family::Wild, &[], 42).unwrap().unwrap(),
(MIT_MAGIC_COOKIE_1.to_vec(), b"1234".to_vec()));
}

Expand Down

0 comments on commit 1e6289f

Please # to comment.