Skip to content

Commit 973999d

Browse files
committed
Revert "argument passed by reference, more efficient if passed by value"
This reverts commit fd252c1.
1 parent 82dc236 commit 973999d

File tree

5 files changed

+19
-19
lines changed

5 files changed

+19
-19
lines changed

src/addr.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,31 +148,31 @@ impl VirtAddr {
148148

149149
/// Returns the 12-bit page offset of this virtual address.
150150
#[inline]
151-
pub fn page_offset(self) -> PageOffset {
151+
pub fn page_offset(&self) -> PageOffset {
152152
PageOffset::new_truncate(self.0 as u16)
153153
}
154154

155155
/// Returns the 9-bit level 1 page table index.
156156
#[inline]
157-
pub fn p1_index(self) -> PageTableIndex {
157+
pub fn p1_index(&self) -> PageTableIndex {
158158
PageTableIndex::new_truncate((self.0 >> 12) as u16)
159159
}
160160

161161
/// Returns the 9-bit level 2 page table index.
162162
#[inline]
163-
pub fn p2_index(self) -> PageTableIndex {
163+
pub fn p2_index(&self) -> PageTableIndex {
164164
PageTableIndex::new_truncate((self.0 >> 12 >> 9) as u16)
165165
}
166166

167167
/// Returns the 9-bit level 3 page table index.
168168
#[inline]
169-
pub fn p3_index(self) -> PageTableIndex {
169+
pub fn p3_index(&self) -> PageTableIndex {
170170
PageTableIndex::new_truncate((self.0 >> 12 >> 9 >> 9) as u16)
171171
}
172172

173173
/// Returns the 9-bit level 4 page table index.
174174
#[inline]
175-
pub fn p4_index(self) -> PageTableIndex {
175+
pub fn p4_index(&self) -> PageTableIndex {
176176
PageTableIndex::new_truncate((self.0 >> 12 >> 9 >> 9 >> 9) as u16)
177177
}
178178
}
@@ -289,7 +289,7 @@ impl PhysAddr {
289289

290290
/// Convenience method for checking if a physical address is null.
291291
#[inline]
292-
pub fn is_null(self) -> bool {
292+
pub fn is_null(&self) -> bool {
293293
self.0 == 0
294294
}
295295

src/instructions/random.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ impl RdRand {
2121
/// Uniformly sampled u64.
2222
/// May fail in rare circumstances or heavy load.
2323
#[inline]
24-
pub fn get_u64(self) -> Option<u64> {
24+
pub fn get_u64(&self) -> Option<u64> {
2525
let mut res: u64 = 0;
2626
unsafe {
2727
match core::arch::x86_64::_rdrand64_step(&mut res) {
@@ -36,7 +36,7 @@ impl RdRand {
3636
/// Uniformly sampled u32.
3737
/// May fail in rare circumstances or heavy load.
3838
#[inline]
39-
pub fn get_u32(self) -> Option<u32> {
39+
pub fn get_u32(&self) -> Option<u32> {
4040
let mut res: u32 = 0;
4141
unsafe {
4242
match core::arch::x86_64::_rdrand32_step(&mut res) {
@@ -51,7 +51,7 @@ impl RdRand {
5151
/// Uniformly sampled u16.
5252
/// May fail in rare circumstances or heavy load.
5353
#[inline]
54-
pub fn get_u16(self) -> Option<u16> {
54+
pub fn get_u16(&self) -> Option<u16> {
5555
let mut res: u16 = 0;
5656
unsafe {
5757
match core::arch::x86_64::_rdrand16_step(&mut res) {

src/structures/gdt.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ impl SegmentSelector {
2727

2828
/// Returns the GDT index.
2929
#[inline]
30-
pub fn index(self) -> u16 {
30+
pub fn index(&self) -> u16 {
3131
self.0 >> 3
3232
}
3333

3434
/// Returns the requested privilege level.
3535
#[inline]
36-
pub fn rpl(self) -> PrivilegeLevel {
36+
pub fn rpl(&self) -> PrivilegeLevel {
3737
PrivilegeLevel::from_u16(self.0.get_bits(0..2))
3838
}
3939

src/structures/paging/frame.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ impl<S: PageSize> PhysFrame<S> {
3737

3838
/// Returns the start address of the frame.
3939
#[inline]
40-
pub fn start_address(self) -> PhysAddr {
40+
pub fn start_address(&self) -> PhysAddr {
4141
self.start_address
4242
}
4343

4444
/// Returns the size the frame (4KB, 2MB or 1GB).
4545
#[inline]
46-
pub fn size(self) -> u64 {
46+
pub fn size(&self) -> u64 {
4747
S::SIZE
4848
}
4949

src/structures/paging/page.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,14 @@ impl<S: PageSize> Page<S> {
8585

8686
/// Returns the start address of the page.
8787
#[inline]
88-
pub fn start_address(self) -> VirtAddr {
88+
pub fn start_address(&self) -> VirtAddr {
8989
self.start_address
9090
}
9191

9292
/// Returns the size the page (4KB, 2MB or 1GB).
9393
#[cfg(feature = "const_fn")]
9494
#[inline]
95-
pub const fn size(self) -> u64 {
95+
pub const fn size(&self) -> u64 {
9696
S::SIZE
9797
}
9898

@@ -105,13 +105,13 @@ impl<S: PageSize> Page<S> {
105105

106106
/// Returns the level 4 page table index of this page.
107107
#[inline]
108-
pub fn p4_index(self) -> PageTableIndex {
108+
pub fn p4_index(&self) -> PageTableIndex {
109109
self.start_address().p4_index()
110110
}
111111

112112
/// Returns the level 3 page table index of this page.
113113
#[inline]
114-
pub fn p3_index(self) -> PageTableIndex {
114+
pub fn p3_index(&self) -> PageTableIndex {
115115
self.start_address().p3_index()
116116
}
117117

@@ -131,7 +131,7 @@ impl<S: PageSize> Page<S> {
131131
impl<S: NotGiantPageSize> Page<S> {
132132
/// Returns the level 2 page table index of this page.
133133
#[inline]
134-
pub fn p2_index(self) -> PageTableIndex {
134+
pub fn p2_index(&self) -> PageTableIndex {
135135
self.start_address().p2_index()
136136
}
137137
}
@@ -188,7 +188,7 @@ impl Page<Size4KiB> {
188188

189189
/// Returns the level 1 page table index of this page.
190190
#[inline]
191-
pub fn p1_index(self) -> PageTableIndex {
191+
pub fn p1_index(&self) -> PageTableIndex {
192192
self.start_address().p1_index()
193193
}
194194
}

0 commit comments

Comments
 (0)