Skip to content

Commit 73852ec

Browse files
committed
Inline more functions
Add #[inline] to more functions which seem like they should be inlined. Signed-off-by: Ayush <ayushsingh1325@gmail.com>
1 parent 36c628f commit 73852ec

File tree

11 files changed

+105
-4
lines changed

11 files changed

+105
-4
lines changed

library/std/src/sys/uefi/args.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ pub fn args() -> Args {
4343
/// This function was tested for equivalence to the C/C++ parsing rules using an
4444
/// extensive test suite available at
4545
/// <https://github.com/ChrisDenton/winarg/tree/std>.
46+
#[inline]
4647
fn parse_lp_cmd_line<'a, F: Fn() -> OsString>(
4748
lp_cmd_line: Option<Ucs2Units<'a>>,
4849
exe_name: F,
@@ -146,28 +147,35 @@ fn parse_lp_cmd_line<'a, F: Fn() -> OsString>(
146147
}
147148

148149
impl fmt::Debug for Args {
150+
#[inline]
149151
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
150152
self.parsed_args_list.as_slice().fmt(f)
151153
}
152154
}
153155

154156
impl Iterator for Args {
155157
type Item = OsString;
158+
159+
#[inline]
156160
fn next(&mut self) -> Option<OsString> {
157161
self.parsed_args_list.next()
158162
}
163+
164+
#[inline]
159165
fn size_hint(&self) -> (usize, Option<usize>) {
160166
self.parsed_args_list.size_hint()
161167
}
162168
}
163169

164170
impl DoubleEndedIterator for Args {
171+
#[inline]
165172
fn next_back(&mut self) -> Option<OsString> {
166173
self.parsed_args_list.next_back()
167174
}
168175
}
169176

170177
impl ExactSizeIterator for Args {
178+
#[inline]
171179
fn len(&self) -> usize {
172180
self.parsed_args_list.len()
173181
}

library/std/src/sys/uefi/fs.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,26 +66,32 @@ pub struct DirBuilder {
6666
}
6767

6868
impl FileAttr {
69+
#[inline]
6970
pub fn size(&self) -> u64 {
7071
self.size
7172
}
7273

74+
#[inline]
7375
pub fn perm(&self) -> FilePermissions {
7476
self.perm
7577
}
7678

79+
#[inline]
7780
pub fn file_type(&self) -> FileType {
7881
self.file_type
7982
}
8083

84+
#[inline]
8185
pub fn modified(&self) -> io::Result<SystemTime> {
8286
Ok(self.file_times.modification_time)
8387
}
8488

89+
#[inline]
8590
pub fn accessed(&self) -> io::Result<SystemTime> {
8691
Ok(self.file_times.last_accessed_time)
8792
}
8893

94+
#[inline]
8995
pub fn created(&self) -> io::Result<SystemTime> {
9096
Ok(self.created_time)
9197
}
@@ -107,10 +113,12 @@ impl From<&file::Info> for FileAttr {
107113
}
108114

109115
impl FilePermissions {
116+
#[inline]
110117
pub fn readonly(&self) -> bool {
111118
self.attr & file::READ_ONLY != 0
112119
}
113120

121+
#[inline]
114122
pub fn set_readonly(&mut self, readonly: bool) {
115123
if readonly {
116124
self.attr |= file::READ_ONLY;
@@ -121,22 +129,26 @@ impl FilePermissions {
121129
}
122130

123131
impl FileType {
132+
#[inline]
124133
pub fn is_dir(&self) -> bool {
125134
self.attr & file::DIRECTORY != 0
126135
}
127136

128137
// Not sure if Archive is a file
138+
#[inline]
129139
pub fn is_file(&self) -> bool {
130140
!self.is_dir()
131141
}
132142

133143
// Doesn't seem like symlink can be detected/supported.
144+
#[inline]
134145
pub fn is_symlink(&self) -> bool {
135146
false
136147
}
137148
}
138149

139150
impl fmt::Debug for ReadDir {
151+
#[inline]
140152
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
141153
fmt::Debug::fmt(&self.path, f)
142154
}
@@ -163,39 +175,48 @@ impl Iterator for ReadDir {
163175
}
164176

165177
impl FileTimes {
178+
#[inline]
166179
pub fn set_accessed(&mut self, t: SystemTime) {
167180
self.last_accessed_time = t;
168181
}
182+
183+
#[inline]
169184
pub fn set_modified(&mut self, t: SystemTime) {
170185
self.modification_time = t;
171186
}
172187
}
173188

174189
impl Default for FileTimes {
190+
#[inline]
175191
fn default() -> Self {
176192
Self { last_accessed_time: UNIX_EPOCH, modification_time: UNIX_EPOCH }
177193
}
178194
}
179195

180196
impl DirEntry {
197+
#[inline]
181198
pub fn path(&self) -> PathBuf {
182199
self.path.clone()
183200
}
184201

202+
#[inline]
185203
pub fn file_name(&self) -> OsString {
186204
self.name.clone()
187205
}
188206

207+
#[inline]
189208
pub fn metadata(&self) -> io::Result<FileAttr> {
190209
Ok(self.attr)
191210
}
192211

212+
#[inline]
193213
pub fn file_type(&self) -> io::Result<FileType> {
194214
Ok(self.attr.file_type())
195215
}
196216
}
197217

198218
impl OpenOptions {
219+
#[inline]
199220
pub fn new() -> OpenOptions {
200221
// These options open file in readonly mode
201222
OpenOptions {
@@ -207,6 +228,7 @@ impl OpenOptions {
207228
}
208229
}
209230

231+
#[inline]
210232
pub fn read(&mut self, read: bool) {
211233
if read {
212234
self.open_mode |= file::MODE_READ;
@@ -215,6 +237,7 @@ impl OpenOptions {
215237
}
216238
}
217239

240+
#[inline]
218241
pub fn write(&mut self, write: bool) {
219242
if write {
220243
self.open_mode |= file::MODE_WRITE;
@@ -228,10 +251,12 @@ impl OpenOptions {
228251
self.append = append;
229252
}
230253

254+
#[inline]
231255
pub fn truncate(&mut self, truncate: bool) {
232256
self.truncate = truncate;
233257
}
234258

259+
#[inline]
235260
pub fn create(&mut self, create: bool) {
236261
if create {
237262
self.open_mode |= file::MODE_CREATE;
@@ -274,14 +299,17 @@ impl File {
274299
Ok(FileAttr::from(info.as_ref()))
275300
}
276301

302+
#[inline]
277303
pub fn fsync(&self) -> io::Result<()> {
278304
self.ptr.flush()
279305
}
280306

307+
#[inline]
281308
pub fn datasync(&self) -> io::Result<()> {
282309
self.fsync()
283310
}
284311

312+
#[inline]
285313
pub fn truncate(&self, size: u64) -> io::Result<()> {
286314
self.ptr.set_file_size(size)
287315
}
@@ -292,10 +320,12 @@ impl File {
292320
Ok(buf_len)
293321
}
294322

323+
#[inline]
295324
pub fn read_vectored(&self, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
296325
crate::io::default_read_vectored(|buf| self.read(buf), bufs)
297326
}
298327

328+
#[inline]
299329
pub fn is_read_vectored(&self) -> bool {
300330
false
301331
}
@@ -313,18 +343,22 @@ impl File {
313343
Ok(())
314344
}
315345

346+
#[inline]
316347
pub fn write(&self, buf: &[u8]) -> io::Result<usize> {
317348
self.ptr.write(buf)
318349
}
319350

351+
#[inline]
320352
pub fn write_vectored(&self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
321353
crate::io::default_write_vectored(|buf| self.write(buf), bufs)
322354
}
323355

356+
#[inline]
324357
pub fn is_write_vectored(&self) -> bool {
325358
false
326359
}
327360

361+
#[inline]
328362
pub fn flush(&self) -> io::Result<()> {
329363
Ok(())
330364
}
@@ -343,6 +377,7 @@ impl File {
343377
unsupported()
344378
}
345379

380+
#[inline]
346381
pub fn set_permissions(&self, perm: FilePermissions) -> io::Result<()> {
347382
self.ptr.set_file_attr(perm.attr)
348383
}
@@ -353,6 +388,7 @@ impl File {
353388
}
354389

355390
impl DirBuilder {
391+
#[inline]
356392
pub fn new() -> DirBuilder {
357393
DirBuilder {
358394
attr: file::DIRECTORY,
@@ -459,6 +495,7 @@ pub fn stat(p: &Path) -> io::Result<FileAttr> {
459495
}
460496

461497
// Shoule be same as stat since symlinks are not implemented anyway
498+
#[inline]
462499
pub fn lstat(p: &Path) -> io::Result<FileAttr> {
463500
stat(p)
464501
}
@@ -531,6 +568,7 @@ mod uefi_fs {
531568
}
532569

533570
impl FileProtocol {
571+
#[inline]
534572
fn new(inner: NonNull<file::Protocol>) -> FileProtocol {
535573
FileProtocol { inner }
536574
}
@@ -686,10 +724,12 @@ mod uefi_fs {
686724
Ok(buffer_size)
687725
}
688726

727+
#[inline]
689728
pub fn read<T>(&self, buf: &mut [T], buffer_size: &mut usize) -> io::Result<()> {
690729
unsafe { Self::read_raw(self.inner.as_ptr(), buffer_size, buf.as_mut_ptr().cast()) }
691730
}
692731

732+
#[inline]
693733
pub fn flush(&self) -> io::Result<()> {
694734
unsafe { Self::flush_raw(self.inner.as_ptr()) }
695735
}

library/std/src/sys/uefi/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,13 @@ pub fn init(_argc: isize, _argv: *const *const u8) {}
5454
// NOTE: this is not guaranteed to run, for example when the program aborts.
5555
pub unsafe fn cleanup() {}
5656

57-
pub fn unsupported<T>() -> std_io::Result<T> {
57+
#[inline]
58+
pub const fn unsupported<T>() -> std_io::Result<T> {
5859
Err(unsupported_err())
5960
}
6061

61-
pub fn unsupported_err() -> std_io::Error {
62+
#[inline]
63+
pub const fn unsupported_err() -> std_io::Error {
6264
std_io::const_io_error!(
6365
std_io::ErrorKind::Unsupported,
6466
"operation not supported on this platform",
@@ -118,6 +120,7 @@ pub extern "C" fn __rust_abort() {
118120
abort_internal();
119121
}
120122

123+
#[inline]
121124
pub fn hashmap_random_keys() -> (u64, u64) {
122125
unsafe { (get_random().unwrap_or(1), get_random().unwrap_or(2)) }
123126
}

library/std/src/sys/uefi/net/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ mod uefi_service_binding {
1919
}
2020

2121
impl ServiceBinding {
22+
#[inline]
2223
pub fn new(
2324
service_binding_guid: r_efi::efi::Guid,
2425
handle: NonNull<crate::ffi::c_void>,

library/std/src/sys/uefi/net/tcp.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,24 +117,28 @@ impl TcpProtocol {
117117
Ok((stream, SocketAddr::from(socket_addr)))
118118
}
119119

120+
#[inline]
120121
pub fn read(&self, buf: &mut [u8]) -> io::Result<usize> {
121122
match self {
122123
TcpProtocol::V4(x) => x.receive(buf),
123124
}
124125
}
125126

127+
#[inline]
126128
pub fn read_vectored(&self, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
127129
match self {
128130
TcpProtocol::V4(x) => x.receive_vectored(bufs),
129131
}
130132
}
131133

134+
#[inline]
132135
pub fn write(&self, buf: &[u8]) -> io::Result<usize> {
133136
match self {
134137
TcpProtocol::V4(x) => x.transmit(buf),
135138
}
136139
}
137140

141+
#[inline]
138142
pub fn write_vectored(&self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
139143
match self {
140144
TcpProtocol::V4(x) => x.transmit_vectored(bufs),
@@ -151,12 +155,14 @@ impl TcpProtocol {
151155
}
152156
}
153157

158+
#[inline]
154159
pub fn peer_addr(&self) -> io::Result<SocketAddr> {
155160
match self {
156161
TcpProtocol::V4(x) => Ok(x.remote_socket()?.into()),
157162
}
158163
}
159164

165+
#[inline]
160166
pub fn local_addr(&self) -> io::Result<SocketAddr> {
161167
match self {
162168
TcpProtocol::V4(x) => Ok(x.station_socket()?.into()),
@@ -195,6 +201,7 @@ impl TcpProtocol {
195201
}
196202

197203
impl From<tcp4::Tcp4Protocol> for TcpProtocol {
204+
#[inline]
198205
fn from(t: tcp4::Tcp4Protocol) -> Self {
199206
Self::V4(t)
200207
}

library/std/src/sys/uefi/net/tcp4.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ impl Tcp4Protocol {
5959
unsafe { Self::config_raw(self.protocol.as_ptr(), config) }
6060
}
6161

62+
#[inline]
6263
pub fn reset(&self) -> io::Result<()> {
6364
unsafe { Self::config_raw(self.protocol.as_ptr(), crate::ptr::null_mut()) }
6465
}
@@ -361,6 +362,7 @@ impl Tcp4Protocol {
361362
))
362363
}
363364

365+
#[inline]
364366
fn new(
365367
protocol: NonNull<tcp4::Protocol>,
366368
service_binding: ServiceBinding,

0 commit comments

Comments
 (0)