Skip to content

Commit 3399264

Browse files
committed
add #[inline] to a bunch of functions
1 parent 554c806 commit 3399264

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

src/lib.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,17 @@ impl<T> VolatilePtr<'_, T>
145145
where
146146
T: ?Sized,
147147
{
148+
#[inline]
148149
pub unsafe fn new_read_write(pointer: NonNull<T>) -> VolatilePtr<'static, T> {
149150
unsafe { VolatilePtr::new_with_access(pointer, Access::read_write()) }
150151
}
151152

153+
#[inline]
152154
pub const unsafe fn new_read_only(pointer: NonNull<T>) -> VolatilePtr<'static, T, ReadOnly> {
153155
unsafe { VolatilePtr::new_with_access(pointer, Access::read_only()) }
154156
}
155157

158+
#[inline]
156159
pub const unsafe fn new_write_only(pointer: NonNull<T>) -> VolatilePtr<'static, T, WriteOnly> {
157160
unsafe { VolatilePtr::new_with_access(pointer, Access::write_only()) }
158161
}
@@ -180,6 +183,7 @@ where
180183
/// volatile.write(1);
181184
/// assert_eq!(volatile.read(), 1);
182185
/// ```
186+
#[inline]
183187
pub const unsafe fn new_with_access<A>(
184188
pointer: NonNull<T>,
185189
access: A,
@@ -188,6 +192,7 @@ where
188192
unsafe { Self::new_generic(pointer) }
189193
}
190194

195+
#[inline]
191196
pub const unsafe fn new_generic<'a, A>(pointer: NonNull<T>) -> VolatilePtr<'a, T, A> {
192197
VolatilePtr {
193198
pointer,
@@ -196,13 +201,15 @@ where
196201
}
197202
}
198203

204+
#[inline]
199205
pub fn from_ref<'a>(reference: &'a T) -> VolatilePtr<'a, T, ReadOnly>
200206
where
201207
T: 'a,
202208
{
203209
unsafe { VolatilePtr::new_generic(reference.into()) }
204210
}
205211

212+
#[inline]
206213
pub fn from_mut_ref<'a>(reference: &'a mut T) -> VolatilePtr<'a, T>
207214
where
208215
T: 'a,
@@ -238,6 +245,7 @@ where
238245
/// let mut_reference = unsafe { VolatilePtr::new_read_write(NonNull::from(&mut value)) };
239246
/// assert_eq!(mut_reference.read(), 50);
240247
/// ```
248+
#[inline]
241249
pub fn read(&self) -> T
242250
where
243251
R: access::Safe,
@@ -265,6 +273,7 @@ where
265273
///
266274
/// assert_eq!(volatile.read(), 50);
267275
/// ```
276+
#[inline]
268277
pub fn write(&mut self, value: T)
269278
where
270279
W: access::Safe,
@@ -290,6 +299,7 @@ where
290299
///
291300
/// assert_eq!(volatile.read(), 43);
292301
/// ```
302+
#[inline]
293303
pub fn update<F>(&mut self, f: F)
294304
where
295305
R: access::Safe,
@@ -331,6 +341,7 @@ where
331341
///
332342
/// assert_eq!(unsafe { *unwrapped }, 50); // non volatile access, be careful!
333343
/// ```
344+
#[inline]
334345
pub fn as_ptr(&self) -> NonNull<T> {
335346
self.pointer
336347
}
@@ -382,6 +393,7 @@ where
382393
/// value
383394
/// })};
384395
/// ```
396+
#[inline]
385397
pub unsafe fn map<'a, F, U>(&'a self, f: F) -> VolatilePtr<'a, U, Access<R, access::NoAccess>>
386398
where
387399
F: FnOnce(NonNull<T>) -> NonNull<U>,
@@ -391,6 +403,7 @@ where
391403
}
392404

393405
#[cfg(feature = "very_unstable")]
406+
#[inline]
394407
pub const unsafe fn map_const<'a, F, U>(
395408
&'a self,
396409
f: F,
@@ -402,6 +415,7 @@ where
402415
unsafe { VolatilePtr::new_generic(f(self.pointer)) }
403416
}
404417

418+
#[inline]
405419
pub unsafe fn map_mut<F, U>(&mut self, f: F) -> VolatilePtr<U, Access<R, W>>
406420
where
407421
F: FnOnce(NonNull<T>) -> NonNull<U>,
@@ -411,6 +425,7 @@ where
411425
}
412426

413427
#[cfg(feature = "very_unstable")]
428+
#[inline]
414429
pub const unsafe fn map_mut_const<F, U>(&mut self, f: F) -> VolatilePtr<U, Access<R, W>>
415430
where
416431
F: FnOnce(NonNull<T>) -> NonNull<U>,
@@ -423,10 +438,12 @@ where
423438
/// Methods for volatile slices
424439
#[cfg(feature = "unstable")]
425440
impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
441+
#[inline]
426442
pub fn len(&self) -> usize {
427443
self.pointer.len()
428444
}
429445

446+
#[inline]
430447
pub fn is_empty(&self) -> bool {
431448
self.pointer.len() == 0
432449
}
@@ -467,6 +484,7 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
467484
/// let subslice = volatile.index(1..);
468485
/// assert_eq!(subslice.index(0).read(), 2);
469486
/// ```
487+
#[inline]
470488
pub fn index<I>(
471489
&self,
472490
index: I,
@@ -480,6 +498,7 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
480498
}
481499

482500
#[cfg(feature = "very_unstable")]
501+
#[inline]
483502
pub const fn index_const(&self, index: usize) -> VolatilePtr<T, Access<R, access::NoAccess>> {
484503
assert!(index < self.pointer.len(), "index out of bounds");
485504
unsafe {
@@ -489,6 +508,7 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
489508
}
490509
}
491510

511+
#[inline]
492512
pub fn index_mut<I>(
493513
&mut self,
494514
index: I,
@@ -502,6 +522,7 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
502522
}
503523

504524
#[cfg(feature = "very_unstable")]
525+
#[inline]
505526
pub const fn index_mut_const(&mut self, index: usize) -> VolatilePtr<T, Access<R, W>> {
506527
assert!(index < self.pointer.len(), "index out of bounds");
507528
unsafe {
@@ -512,6 +533,7 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
512533
}
513534

514535
/// Returns an iterator over the slice.
536+
#[inline]
515537
pub fn iter<'b>(
516538
&'b self,
517539
) -> impl Iterator<Item = VolatilePtr<'b, T, Access<R, access::NoAccess>>> + 'b {
@@ -520,6 +542,7 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
520542
}
521543

522544
/// Returns an iterator that allows modifying each value.
545+
#[inline]
523546
pub fn iter_mut<'b>(
524547
&'b mut self,
525548
) -> impl Iterator<Item = VolatilePtr<'b, T, Access<R, W>>> + 'b {
@@ -563,6 +586,7 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
563586
/// assert_eq!(src, [1, 2]);
564587
/// assert_eq!(dst, [5, 1, 2]);
565588
/// ```
589+
#[inline]
566590
pub fn copy_into_slice(&self, dst: &mut [T])
567591
where
568592
T: Copy,
@@ -620,6 +644,7 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
620644
/// assert_eq!(src, [1, 2, 3, 4]);
621645
/// assert_eq!(dst, [3, 4]);
622646
/// ```
647+
#[inline]
623648
pub fn copy_from_slice(&mut self, src: &[T])
624649
where
625650
T: Copy,
@@ -674,6 +699,7 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
674699
/// volatile.copy_within(1..5, 8);
675700
///
676701
/// assert_eq!(&byte_array, b"Hello, Wello!");
702+
#[inline]
677703
pub fn copy_within(&mut self, src: impl RangeBounds<usize>, dest: usize)
678704
where
679705
T: Copy,
@@ -699,6 +725,7 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
699725
}
700726
}
701727

728+
#[inline]
702729
pub fn split_at(
703730
&self,
704731
mid: usize,
@@ -712,6 +739,7 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
712739
unsafe { self.split_at_unchecked(mid) }
713740
}
714741

742+
#[inline]
715743
pub fn split_at_mut(
716744
&mut self,
717745
mid: usize,
@@ -725,6 +753,7 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
725753
unsafe { self.split_at_mut_unchecked(mid) }
726754
}
727755

756+
#[inline]
728757
unsafe fn split_at_unchecked(
729758
&self,
730759
mid: usize,
@@ -741,6 +770,7 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
741770
}
742771
}
743772

773+
#[inline]
744774
unsafe fn split_at_mut_unchecked(
745775
&mut self,
746776
mid: usize,
@@ -767,6 +797,7 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
767797
}
768798
}
769799

800+
#[inline]
770801
pub fn as_chunks<const N: usize>(
771802
&self,
772803
) -> (
@@ -782,6 +813,7 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
782813
(array_slice, remainder)
783814
}
784815

816+
#[inline]
785817
pub unsafe fn as_chunks_unchecked<const N: usize>(
786818
&self,
787819
) -> VolatilePtr<[[T; N]], Access<R, access::NoAccess>> {
@@ -800,6 +832,7 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
800832
unsafe { VolatilePtr::new_generic(pointer) }
801833
}
802834

835+
#[inline]
803836
pub fn as_chunks_mut<const N: usize>(
804837
&mut self,
805838
) -> (
@@ -815,6 +848,7 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
815848
(array_slice, remainder)
816849
}
817850

851+
#[inline]
818852
pub unsafe fn as_chunks_unchecked_mut<const N: usize>(
819853
&mut self,
820854
) -> VolatilePtr<[[T; N]], Access<R, W>> {
@@ -833,6 +867,7 @@ impl<'a, T, R, W> VolatilePtr<'a, [T], Access<R, W>> {
833867
unsafe { VolatilePtr::new_generic(pointer) }
834868
}
835869

870+
#[inline]
836871
pub unsafe fn as_chunks_unchecked_by_val<const N: usize>(
837872
self,
838873
) -> VolatilePtr<'a, [[T; N]], Access<R, W>> {
@@ -876,6 +911,7 @@ impl<R, W> VolatilePtr<'_, [u8], Access<R, W>> {
876911
/// buf.fill(1);
877912
/// assert_eq!(unsafe { buf.as_ptr().as_mut() }, &mut vec![1; 10]);
878913
/// ```
914+
#[inline]
879915
pub fn fill(&mut self, value: u8)
880916
where
881917
W: access::Safe,
@@ -916,6 +952,7 @@ impl<T, R, W, const N: usize> VolatilePtr<'_, [T; N], Access<R, W>> {
916952
///
917953
/// assert_eq!(dst, [1, 2]);
918954
/// ```
955+
#[inline]
919956
pub fn as_slice(&self) -> VolatilePtr<[T], Access<R, access::NoAccess>> {
920957
unsafe {
921958
self.map(|array| {
@@ -948,6 +985,7 @@ impl<T, R, W, const N: usize> VolatilePtr<'_, [T; N], Access<R, W>> {
948985
///
949986
/// assert_eq!(dst, [1, 2]);
950987
/// ```
988+
#[inline]
951989
pub fn as_slice_mut<'a>(&'a mut self) -> VolatilePtr<'a, [T], Access<R, W>> {
952990
unsafe {
953991
self.map_mut(|array| {
@@ -978,6 +1016,7 @@ where
9781016
/// assert_eq!(read_only.read(), -4);
9791017
/// // read_only.write(10); // compile-time error
9801018
/// ```
1019+
#[inline]
9811020
pub fn read_only(self) -> VolatilePtr<'a, T, Access<R, access::NoAccess>> {
9821021
unsafe { VolatilePtr::new_generic(self.pointer) }
9831022
}
@@ -1002,6 +1041,7 @@ where
10021041
/// field_2.write(14);
10031042
/// // field_2.read(); // compile-time error
10041043
/// ```
1044+
#[inline]
10051045
pub fn write_only(self) -> VolatilePtr<'a, T, Access<access::NoAccess, W>> {
10061046
unsafe { VolatilePtr::new_generic(self.pointer) }
10071047
}
@@ -1012,20 +1052,23 @@ impl<T, R, W> VolatilePtr<'_, T, Access<R, W>>
10121052
where
10131053
T: Copy + ?Sized,
10141054
{
1055+
#[inline]
10151056
pub unsafe fn read_unsafe(&self) -> T
10161057
where
10171058
R: access::Unsafe,
10181059
{
10191060
unsafe { ptr::read_volatile(self.pointer.as_ptr()) }
10201061
}
10211062

1063+
#[inline]
10221064
pub unsafe fn write_unsafe(&mut self, value: T)
10231065
where
10241066
W: access::Unsafe,
10251067
{
10261068
unsafe { ptr::write_volatile(self.pointer.as_ptr(), value) };
10271069
}
10281070

1071+
#[inline]
10291072
pub unsafe fn update_unsafe<F>(&mut self, f: F)
10301073
where
10311074
R: access::Unsafe,

0 commit comments

Comments
 (0)