Skip to content

Commit 96ab22f

Browse files
committed
improve conditional compilation w/o relying on cfg_if
1 parent 98fae22 commit 96ab22f

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

src/lib.rs

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -89,45 +89,48 @@ impl<H, T> HeaderVec<H, T> {
8989
/// Get the length of the vector from a mutable reference. When one has a `&mut
9090
/// HeaderVec`, this is the method is always exact and can be slightly faster than the non
9191
/// mutable `len()`.
92-
#[cfg(feature = "atomic_append")]
93-
#[inline(always)]
94-
pub fn len_exact(&mut self) -> usize {
95-
*self.header_mut().len.get_mut()
96-
}
97-
#[cfg(not(feature = "atomic_append"))]
9892
#[inline(always)]
9993
pub fn len_exact(&mut self) -> usize {
100-
self.header_mut().len
94+
#[cfg(feature = "atomic_append")]
95+
{
96+
*self.header_mut().len.get_mut()
97+
}
98+
#[cfg(not(feature = "atomic_append"))]
99+
{
100+
self.header_mut().len
101+
}
101102
}
102103

103104
/// This gives the length of the `HeaderVec`. This is the non synchronized variant may
104105
/// produce racy results in case another thread atomically appended to
105106
/// `&self`. Nevertheless it is always safe to use.
106-
#[cfg(feature = "atomic_append")]
107107
#[inline(always)]
108108
pub fn len(&self) -> usize {
109-
self.len_atomic_relaxed()
110-
}
111-
#[cfg(not(feature = "atomic_append"))]
112-
#[inline(always)]
113-
pub fn len(&self) -> usize {
114-
self.header().len
109+
#[cfg(feature = "atomic_append")]
110+
{
111+
self.len_atomic_relaxed()
112+
}
113+
#[cfg(not(feature = "atomic_append"))]
114+
{
115+
self.header().len
116+
}
115117
}
116118

117119
/// This gives the length of the `HeaderVec`. With `atomic_append` enabled this gives a
118120
/// exact result *after* another thread atomically appended to this `HeaderVec`. It still
119121
/// requires synchronization because the length may become invalidated when another thread
120122
/// atomically appends data to this `HeaderVec` while we still work with the result of
121123
/// this method.
122-
#[cfg(not(feature = "atomic_append"))]
123-
#[inline(always)]
124-
pub fn len_strict(&self) -> usize {
125-
self.header().len
126-
}
127-
#[cfg(feature = "atomic_append")]
128124
#[inline(always)]
129125
pub fn len_strict(&self) -> usize {
130-
self.len_atomic_acquire()
126+
#[cfg(feature = "atomic_append")]
127+
{
128+
self.len_atomic_acquire()
129+
}
130+
#[cfg(not(feature = "atomic_append"))]
131+
{
132+
self.header().len
133+
}
131134
}
132135

133136
/// Check whenever a `HeaderVec` is empty. This uses a `&mut self` reference and is

0 commit comments

Comments
 (0)