Skip to content

Commit 5f8711c

Browse files
committed
improve conditional compilation w/o relying on cfg_if
1 parent e6bcf06 commit 5f8711c

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

Diff for: src/lib.rs

+24-24
Original file line numberDiff line numberDiff line change
@@ -137,51 +137,51 @@ impl<H, T> HeaderVec<H, T> {
137137
/// Get the length of the vector from a mutable reference. When one has a `&mut
138138
/// HeaderVec`, this is the method is always exact and can be slightly faster than the non
139139
/// mutable `len()`.
140-
#[cfg(feature = "atomic_append")]
141-
#[mutants::skip]
142-
#[inline(always)]
143-
pub fn len_exact(&mut self) -> usize {
144-
*self.header_mut().len.get_mut()
145-
}
146-
#[cfg(not(feature = "atomic_append"))]
147140
#[mutants::skip]
148141
#[inline(always)]
149142
pub fn len_exact(&mut self) -> usize {
150-
self.header_mut().len
143+
#[cfg(feature = "atomic_append")]
144+
{
145+
*self.header_mut().len.get_mut()
146+
}
147+
#[cfg(not(feature = "atomic_append"))]
148+
{
149+
self.header_mut().len
150+
}
151151
}
152152

153153
/// This gives the length of the `HeaderVec`. This is the non synchronized variant may
154154
/// produce racy results in case another thread atomically appended to
155155
/// `&self`. Nevertheless it is always safe to use.
156-
#[cfg(feature = "atomic_append")]
157-
#[mutants::skip]
158-
#[inline(always)]
159-
pub fn len(&self) -> usize {
160-
self.len_atomic_relaxed()
161-
}
162-
#[cfg(not(feature = "atomic_append"))]
163156
#[mutants::skip]
164157
#[inline(always)]
165158
pub fn len(&self) -> usize {
166-
self.header().len
159+
#[cfg(feature = "atomic_append")]
160+
{
161+
self.len_atomic_relaxed()
162+
}
163+
#[cfg(not(feature = "atomic_append"))]
164+
{
165+
self.header().len
166+
}
167167
}
168168

169169
/// This gives the length of the `HeaderVec`. With `atomic_append` enabled this gives a
170170
/// exact result *after* another thread atomically appended to this `HeaderVec`. It still
171171
/// requires synchronization because the length may become invalidated when another thread
172172
/// atomically appends data to this `HeaderVec` while we still work with the result of
173173
/// this method.
174-
#[cfg(not(feature = "atomic_append"))]
175-
#[mutants::skip]
176-
#[inline(always)]
177-
pub fn len_strict(&self) -> usize {
178-
self.header().len
179-
}
180-
#[cfg(feature = "atomic_append")]
181174
#[mutants::skip]
182175
#[inline(always)]
183176
pub fn len_strict(&self) -> usize {
184-
self.len_atomic_acquire()
177+
#[cfg(not(feature = "atomic_append"))]
178+
{
179+
self.header().len
180+
}
181+
#[cfg(feature = "atomic_append")]
182+
{
183+
self.len_atomic_acquire()
184+
}
185185
}
186186

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

0 commit comments

Comments
 (0)