sys_util: guest_address: take self by value in methods
clippy says that it is more efficient. Since self is a u64 in this case,
it is correct.
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Change-Id: Id7674db500a01640f650b239374fe9f83e2bc595
Reviewed-on: https://chromium-review.googlesource.com/1510065
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
diff --git a/sys_util/src/guest_address.rs b/sys_util/src/guest_address.rs
index 3e521ff..1b78e71 100644
--- a/sys_util/src/guest_address.rs
+++ b/sys_util/src/guest_address.rs
@@ -23,34 +23,34 @@
/// let addr = GuestAddress(0x150);
/// assert_eq!(addr.offset_from(base), 0x50u64);
/// ```
- pub fn offset_from(&self, base: GuestAddress) -> u64 {
+ pub fn offset_from(self, base: GuestAddress) -> u64 {
self.0 - base.0
}
/// Returns the address as a u64 offset from 0x0.
/// Use this when a raw number is needed to pass to the kernel.
- pub fn offset(&self) -> u64 {
+ pub fn offset(self) -> u64 {
self.0
}
/// Returns the result of the add or None if there is overflow.
- pub fn checked_add(&self, other: u64) -> Option<GuestAddress> {
+ pub fn checked_add(self, other: u64) -> Option<GuestAddress> {
self.0.checked_add(other).map(GuestAddress)
}
/// Returns the result of the base address + the size.
/// Only use this when `offset` is guaranteed not to overflow.
- pub fn unchecked_add(&self, offset: u64) -> GuestAddress {
+ pub fn unchecked_add(self, offset: u64) -> GuestAddress {
GuestAddress(self.0 + offset)
}
/// Returns the result of the subtraction of None if there is underflow.
- pub fn checked_sub(&self, other: u64) -> Option<GuestAddress> {
+ pub fn checked_sub(self, other: u64) -> Option<GuestAddress> {
self.0.checked_sub(other).map(GuestAddress)
}
/// Returns the bitwise and of the address with the given mask.
- pub fn mask(&self, mask: u64) -> GuestAddress {
+ pub fn mask(self, mask: u64) -> GuestAddress {
GuestAddress(self.0 & mask as u64)
}
}