Skip to content

Commit c97bb82

Browse files
committed
Auto merge of #385 - stepancheg:pub-crate, r=Amanieu
Mark non-private members of mod raw pub(crate) When reading code, make it more clear, what is private and what is public API.
2 parents dcb854f + d369bdd commit c97bb82

File tree

4 files changed

+41
-41
lines changed

4 files changed

+41
-41
lines changed

src/raw/alloc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ mod inner {
77
use core::ptr::NonNull;
88

99
#[allow(clippy::map_err_ignore)]
10-
pub fn do_alloc<A: Allocator>(alloc: &A, layout: Layout) -> Result<NonNull<u8>, ()> {
10+
pub(crate) fn do_alloc<A: Allocator>(alloc: &A, layout: Layout) -> Result<NonNull<u8>, ()> {
1111
match alloc.allocate(layout) {
1212
Ok(ptr) => Ok(ptr.as_non_null_ptr()),
1313
Err(_) => Err(()),
@@ -58,7 +58,7 @@ mod inner {
5858
}
5959
}
6060

61-
pub fn do_alloc<A: Allocator>(alloc: &A, layout: Layout) -> Result<NonNull<u8>, ()> {
61+
pub(crate) fn do_alloc<A: Allocator>(alloc: &A, layout: Layout) -> Result<NonNull<u8>, ()> {
6262
alloc.allocate(layout)
6363
}
6464

src/raw/bitmask.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ use core::intrinsics;
1414
/// performed on counts/indices to normalize this difference. `BITMASK_MASK` is
1515
/// similarly a mask of all the actually-used bits.
1616
#[derive(Copy, Clone)]
17-
pub struct BitMask(pub BitMaskWord);
17+
pub(crate) struct BitMask(pub(crate) BitMaskWord);
1818

1919
#[allow(clippy::use_self)]
2020
impl BitMask {
2121
/// Returns a new `BitMask` with all bits inverted.
2222
#[inline]
2323
#[must_use]
24-
pub fn invert(self) -> Self {
24+
pub(crate) fn invert(self) -> Self {
2525
BitMask(self.0 ^ BITMASK_MASK)
2626
}
2727

@@ -31,7 +31,7 @@ impl BitMask {
3131
#[inline]
3232
#[allow(clippy::cast_ptr_alignment)]
3333
#[cfg(feature = "raw")]
34-
pub unsafe fn flip(&mut self, index: usize) -> bool {
34+
pub(crate) unsafe fn flip(&mut self, index: usize) -> bool {
3535
// NOTE: The + BITMASK_STRIDE - 1 is to set the high bit.
3636
let mask = 1 << (index * BITMASK_STRIDE + BITMASK_STRIDE - 1);
3737
self.0 ^= mask;
@@ -42,18 +42,18 @@ impl BitMask {
4242
/// Returns a new `BitMask` with the lowest bit removed.
4343
#[inline]
4444
#[must_use]
45-
pub fn remove_lowest_bit(self) -> Self {
45+
pub(crate) fn remove_lowest_bit(self) -> Self {
4646
BitMask(self.0 & (self.0 - 1))
4747
}
4848
/// Returns whether the `BitMask` has at least one set bit.
4949
#[inline]
50-
pub fn any_bit_set(self) -> bool {
50+
pub(crate) fn any_bit_set(self) -> bool {
5151
self.0 != 0
5252
}
5353

5454
/// Returns the first set bit in the `BitMask`, if there is one.
5555
#[inline]
56-
pub fn lowest_set_bit(self) -> Option<usize> {
56+
pub(crate) fn lowest_set_bit(self) -> Option<usize> {
5757
if self.0 == 0 {
5858
None
5959
} else {
@@ -65,18 +65,18 @@ impl BitMask {
6565
/// bitmask must not be empty.
6666
#[inline]
6767
#[cfg(feature = "nightly")]
68-
pub unsafe fn lowest_set_bit_nonzero(self) -> usize {
68+
pub(crate) unsafe fn lowest_set_bit_nonzero(self) -> usize {
6969
intrinsics::cttz_nonzero(self.0) as usize / BITMASK_STRIDE
7070
}
7171
#[inline]
7272
#[cfg(not(feature = "nightly"))]
73-
pub unsafe fn lowest_set_bit_nonzero(self) -> usize {
73+
pub(crate) unsafe fn lowest_set_bit_nonzero(self) -> usize {
7474
self.trailing_zeros()
7575
}
7676

7777
/// Returns the number of trailing zeroes in the `BitMask`.
7878
#[inline]
79-
pub fn trailing_zeros(self) -> usize {
79+
pub(crate) fn trailing_zeros(self) -> usize {
8080
// ARM doesn't have a trailing_zeroes instruction, and instead uses
8181
// reverse_bits (RBIT) + leading_zeroes (CLZ). However older ARM
8282
// versions (pre-ARMv7) don't have RBIT and need to emulate it
@@ -91,7 +91,7 @@ impl BitMask {
9191

9292
/// Returns the number of leading zeroes in the `BitMask`.
9393
#[inline]
94-
pub fn leading_zeros(self) -> usize {
94+
pub(crate) fn leading_zeros(self) -> usize {
9595
self.0.leading_zeros() as usize / BITMASK_STRIDE
9696
}
9797
}
@@ -108,7 +108,7 @@ impl IntoIterator for BitMask {
108108

109109
/// Iterator over the contents of a `BitMask`, returning the indices of set
110110
/// bits.
111-
pub struct BitMaskIter(BitMask);
111+
pub(crate) struct BitMaskIter(BitMask);
112112

113113
impl Iterator for BitMaskIter {
114114
type Item = usize;

src/raw/generic.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ type GroupWord = u64;
2020
))]
2121
type GroupWord = u32;
2222

23-
pub type BitMaskWord = GroupWord;
24-
pub const BITMASK_STRIDE: usize = 8;
23+
pub(crate) type BitMaskWord = GroupWord;
24+
pub(crate) const BITMASK_STRIDE: usize = 8;
2525
// We only care about the highest bit of each byte for the mask.
2626
#[allow(clippy::cast_possible_truncation, clippy::unnecessary_cast)]
27-
pub const BITMASK_MASK: BitMaskWord = 0x8080_8080_8080_8080_u64 as GroupWord;
27+
pub(crate) const BITMASK_MASK: BitMaskWord = 0x8080_8080_8080_8080_u64 as GroupWord;
2828

2929
/// Helper function to replicate a byte across a `GroupWord`.
3030
#[inline]
@@ -37,7 +37,7 @@ fn repeat(byte: u8) -> GroupWord {
3737
///
3838
/// This implementation uses a word-sized integer.
3939
#[derive(Copy, Clone)]
40-
pub struct Group(GroupWord);
40+
pub(crate) struct Group(GroupWord);
4141

4242
// We perform all operations in the native endianness, and convert to
4343
// little-endian just before creating a BitMask. The can potentially
@@ -46,14 +46,14 @@ pub struct Group(GroupWord);
4646
#[allow(clippy::use_self)]
4747
impl Group {
4848
/// Number of bytes in the group.
49-
pub const WIDTH: usize = mem::size_of::<Self>();
49+
pub(crate) const WIDTH: usize = mem::size_of::<Self>();
5050

5151
/// Returns a full group of empty bytes, suitable for use as the initial
5252
/// value for an empty hash table.
5353
///
5454
/// This is guaranteed to be aligned to the group size.
5555
#[inline]
56-
pub const fn static_empty() -> &'static [u8; Group::WIDTH] {
56+
pub(crate) const fn static_empty() -> &'static [u8; Group::WIDTH] {
5757
#[repr(C)]
5858
struct AlignedBytes {
5959
_align: [Group; 0],
@@ -69,15 +69,15 @@ impl Group {
6969
/// Loads a group of bytes starting at the given address.
7070
#[inline]
7171
#[allow(clippy::cast_ptr_alignment)] // unaligned load
72-
pub unsafe fn load(ptr: *const u8) -> Self {
72+
pub(crate) unsafe fn load(ptr: *const u8) -> Self {
7373
Group(ptr::read_unaligned(ptr.cast()))
7474
}
7575

7676
/// Loads a group of bytes starting at the given address, which must be
7777
/// aligned to `mem::align_of::<Group>()`.
7878
#[inline]
7979
#[allow(clippy::cast_ptr_alignment)]
80-
pub unsafe fn load_aligned(ptr: *const u8) -> Self {
80+
pub(crate) unsafe fn load_aligned(ptr: *const u8) -> Self {
8181
// FIXME: use align_offset once it stabilizes
8282
debug_assert_eq!(ptr as usize & (mem::align_of::<Self>() - 1), 0);
8383
Group(ptr::read(ptr.cast()))
@@ -87,7 +87,7 @@ impl Group {
8787
/// aligned to `mem::align_of::<Group>()`.
8888
#[inline]
8989
#[allow(clippy::cast_ptr_alignment)]
90-
pub unsafe fn store_aligned(self, ptr: *mut u8) {
90+
pub(crate) unsafe fn store_aligned(self, ptr: *mut u8) {
9191
// FIXME: use align_offset once it stabilizes
9292
debug_assert_eq!(ptr as usize & (mem::align_of::<Self>() - 1), 0);
9393
ptr::write(ptr.cast(), self.0);
@@ -104,7 +104,7 @@ impl Group {
104104
/// - This only happens if there is at least 1 true match.
105105
/// - The chance of this happening is very low (< 1% chance per byte).
106106
#[inline]
107-
pub fn match_byte(self, byte: u8) -> BitMask {
107+
pub(crate) fn match_byte(self, byte: u8) -> BitMask {
108108
// This algorithm is derived from
109109
// https://graphics.stanford.edu/~seander/bithacks.html##ValueInWord
110110
let cmp = self.0 ^ repeat(byte);
@@ -114,7 +114,7 @@ impl Group {
114114
/// Returns a `BitMask` indicating all bytes in the group which are
115115
/// `EMPTY`.
116116
#[inline]
117-
pub fn match_empty(self) -> BitMask {
117+
pub(crate) fn match_empty(self) -> BitMask {
118118
// If the high bit is set, then the byte must be either:
119119
// 1111_1111 (EMPTY) or 1000_0000 (DELETED).
120120
// So we can just check if the top two bits are 1 by ANDing them.
@@ -124,14 +124,14 @@ impl Group {
124124
/// Returns a `BitMask` indicating all bytes in the group which are
125125
/// `EMPTY` or `DELETED`.
126126
#[inline]
127-
pub fn match_empty_or_deleted(self) -> BitMask {
127+
pub(crate) fn match_empty_or_deleted(self) -> BitMask {
128128
// A byte is EMPTY or DELETED iff the high bit is set
129129
BitMask((self.0 & repeat(0x80)).to_le())
130130
}
131131

132132
/// Returns a `BitMask` indicating all bytes in the group which are full.
133133
#[inline]
134-
pub fn match_full(self) -> BitMask {
134+
pub(crate) fn match_full(self) -> BitMask {
135135
self.match_empty_or_deleted().invert()
136136
}
137137

@@ -140,7 +140,7 @@ impl Group {
140140
/// - `DELETED => EMPTY`
141141
/// - `FULL => DELETED`
142142
#[inline]
143-
pub fn convert_special_to_empty_and_full_to_deleted(self) -> Self {
143+
pub(crate) fn convert_special_to_empty_and_full_to_deleted(self) -> Self {
144144
// Map high_bit = 1 (EMPTY or DELETED) to 1111_1111
145145
// and high_bit = 0 (FULL) to 1000_0000
146146
//

src/raw/sse2.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,30 @@ use core::arch::x86;
77
#[cfg(target_arch = "x86_64")]
88
use core::arch::x86_64 as x86;
99

10-
pub type BitMaskWord = u16;
11-
pub const BITMASK_STRIDE: usize = 1;
12-
pub const BITMASK_MASK: BitMaskWord = 0xffff;
10+
pub(crate) type BitMaskWord = u16;
11+
pub(crate) const BITMASK_STRIDE: usize = 1;
12+
pub(crate) const BITMASK_MASK: BitMaskWord = 0xffff;
1313

1414
/// Abstraction over a group of control bytes which can be scanned in
1515
/// parallel.
1616
///
1717
/// This implementation uses a 128-bit SSE value.
1818
#[derive(Copy, Clone)]
19-
pub struct Group(x86::__m128i);
19+
pub(crate) struct Group(x86::__m128i);
2020

2121
// FIXME: https://github.com/rust-lang/rust-clippy/issues/3859
2222
#[allow(clippy::use_self)]
2323
impl Group {
2424
/// Number of bytes in the group.
25-
pub const WIDTH: usize = mem::size_of::<Self>();
25+
pub(crate) const WIDTH: usize = mem::size_of::<Self>();
2626

2727
/// Returns a full group of empty bytes, suitable for use as the initial
2828
/// value for an empty hash table.
2929
///
3030
/// This is guaranteed to be aligned to the group size.
3131
#[inline]
3232
#[allow(clippy::items_after_statements)]
33-
pub const fn static_empty() -> &'static [u8; Group::WIDTH] {
33+
pub(crate) const fn static_empty() -> &'static [u8; Group::WIDTH] {
3434
#[repr(C)]
3535
struct AlignedBytes {
3636
_align: [Group; 0],
@@ -46,15 +46,15 @@ impl Group {
4646
/// Loads a group of bytes starting at the given address.
4747
#[inline]
4848
#[allow(clippy::cast_ptr_alignment)] // unaligned load
49-
pub unsafe fn load(ptr: *const u8) -> Self {
49+
pub(crate) unsafe fn load(ptr: *const u8) -> Self {
5050
Group(x86::_mm_loadu_si128(ptr.cast()))
5151
}
5252

5353
/// Loads a group of bytes starting at the given address, which must be
5454
/// aligned to `mem::align_of::<Group>()`.
5555
#[inline]
5656
#[allow(clippy::cast_ptr_alignment)]
57-
pub unsafe fn load_aligned(ptr: *const u8) -> Self {
57+
pub(crate) unsafe fn load_aligned(ptr: *const u8) -> Self {
5858
// FIXME: use align_offset once it stabilizes
5959
debug_assert_eq!(ptr as usize & (mem::align_of::<Self>() - 1), 0);
6060
Group(x86::_mm_load_si128(ptr.cast()))
@@ -64,7 +64,7 @@ impl Group {
6464
/// aligned to `mem::align_of::<Group>()`.
6565
#[inline]
6666
#[allow(clippy::cast_ptr_alignment)]
67-
pub unsafe fn store_aligned(self, ptr: *mut u8) {
67+
pub(crate) unsafe fn store_aligned(self, ptr: *mut u8) {
6868
// FIXME: use align_offset once it stabilizes
6969
debug_assert_eq!(ptr as usize & (mem::align_of::<Self>() - 1), 0);
7070
x86::_mm_store_si128(ptr.cast(), self.0);
@@ -73,7 +73,7 @@ impl Group {
7373
/// Returns a `BitMask` indicating all bytes in the group which have
7474
/// the given value.
7575
#[inline]
76-
pub fn match_byte(self, byte: u8) -> BitMask {
76+
pub(crate) fn match_byte(self, byte: u8) -> BitMask {
7777
#[allow(
7878
clippy::cast_possible_wrap, // byte: u8 as i8
7979
// byte: i32 as u16
@@ -91,14 +91,14 @@ impl Group {
9191
/// Returns a `BitMask` indicating all bytes in the group which are
9292
/// `EMPTY`.
9393
#[inline]
94-
pub fn match_empty(self) -> BitMask {
94+
pub(crate) fn match_empty(self) -> BitMask {
9595
self.match_byte(EMPTY)
9696
}
9797

9898
/// Returns a `BitMask` indicating all bytes in the group which are
9999
/// `EMPTY` or `DELETED`.
100100
#[inline]
101-
pub fn match_empty_or_deleted(self) -> BitMask {
101+
pub(crate) fn match_empty_or_deleted(self) -> BitMask {
102102
#[allow(
103103
// byte: i32 as u16
104104
// note: _mm_movemask_epi8 returns a 16-bit mask in a i32, the
@@ -114,7 +114,7 @@ impl Group {
114114

115115
/// Returns a `BitMask` indicating all bytes in the group which are full.
116116
#[inline]
117-
pub fn match_full(&self) -> BitMask {
117+
pub(crate) fn match_full(&self) -> BitMask {
118118
self.match_empty_or_deleted().invert()
119119
}
120120

@@ -123,7 +123,7 @@ impl Group {
123123
/// - `DELETED => EMPTY`
124124
/// - `FULL => DELETED`
125125
#[inline]
126-
pub fn convert_special_to_empty_and_full_to_deleted(self) -> Self {
126+
pub(crate) fn convert_special_to_empty_and_full_to_deleted(self) -> Self {
127127
// Map high_bit = 1 (EMPTY or DELETED) to 1111_1111
128128
// and high_bit = 0 (FULL) to 1000_0000
129129
//

0 commit comments

Comments
 (0)