/rust/registry/src/index.crates.io-6f17d22bba15001f/hashbrown-0.12.3/src/raw/alloc.rs
Line | Count | Source |
1 | | pub(crate) use self::inner::{do_alloc, Allocator, Global}; |
2 | | |
3 | | #[cfg(feature = "nightly")] |
4 | | mod inner { |
5 | | use crate::alloc::alloc::Layout; |
6 | | pub use crate::alloc::alloc::{Allocator, Global}; |
7 | | use core::ptr::NonNull; |
8 | | |
9 | | #[allow(clippy::map_err_ignore)] |
10 | | pub fn do_alloc<A: Allocator>(alloc: &A, layout: Layout) -> Result<NonNull<u8>, ()> { |
11 | | match alloc.allocate(layout) { |
12 | | Ok(ptr) => Ok(ptr.as_non_null_ptr()), |
13 | | Err(_) => Err(()), |
14 | | } |
15 | | } |
16 | | |
17 | | #[cfg(feature = "bumpalo")] |
18 | | unsafe impl Allocator for crate::BumpWrapper<'_> { |
19 | | #[inline] |
20 | | fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, core::alloc::AllocError> { |
21 | | match self.0.try_alloc_layout(layout) { |
22 | | Ok(ptr) => Ok(NonNull::slice_from_raw_parts(ptr, layout.size())), |
23 | | Err(_) => Err(core::alloc::AllocError), |
24 | | } |
25 | | } |
26 | | #[inline] |
27 | | unsafe fn deallocate(&self, _ptr: NonNull<u8>, _layout: Layout) {} |
28 | | } |
29 | | } |
30 | | |
31 | | #[cfg(not(feature = "nightly"))] |
32 | | mod inner { |
33 | | use crate::alloc::alloc::{alloc, dealloc, Layout}; |
34 | | use core::ptr::NonNull; |
35 | | |
36 | | #[allow(clippy::missing_safety_doc)] // not exposed outside of this crate |
37 | | pub unsafe trait Allocator { |
38 | | fn allocate(&self, layout: Layout) -> Result<NonNull<u8>, ()>; |
39 | | unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout); |
40 | | } |
41 | | |
42 | | #[derive(Copy, Clone)] |
43 | | pub struct Global; |
44 | | unsafe impl Allocator for Global { |
45 | | #[inline] |
46 | 87.1k | fn allocate(&self, layout: Layout) -> Result<NonNull<u8>, ()> { |
47 | 87.1k | unsafe { NonNull::new(alloc(layout)).ok_or(()) } |
48 | 87.1k | } <hashbrown::raw::inner::alloc::inner::Global as hashbrown::raw::inner::alloc::inner::Allocator>::allocate Line | Count | Source | 46 | 185 | fn allocate(&self, layout: Layout) -> Result<NonNull<u8>, ()> { | 47 | 185 | unsafe { NonNull::new(alloc(layout)).ok_or(()) } | 48 | 185 | } |
Unexecuted instantiation: <hashbrown::raw::inner::alloc::inner::Global as hashbrown::raw::inner::alloc::inner::Allocator>::allocate Unexecuted instantiation: <hashbrown::raw::inner::alloc::inner::Global as hashbrown::raw::inner::alloc::inner::Allocator>::allocate Unexecuted instantiation: <hashbrown::raw::inner::alloc::inner::Global as hashbrown::raw::inner::alloc::inner::Allocator>::allocate <hashbrown::raw::inner::alloc::inner::Global as hashbrown::raw::inner::alloc::inner::Allocator>::allocate Line | Count | Source | 46 | 28.4k | fn allocate(&self, layout: Layout) -> Result<NonNull<u8>, ()> { | 47 | 28.4k | unsafe { NonNull::new(alloc(layout)).ok_or(()) } | 48 | 28.4k | } |
<hashbrown::raw::inner::alloc::inner::Global as hashbrown::raw::inner::alloc::inner::Allocator>::allocate Line | Count | Source | 46 | 25.4k | fn allocate(&self, layout: Layout) -> Result<NonNull<u8>, ()> { | 47 | 25.4k | unsafe { NonNull::new(alloc(layout)).ok_or(()) } | 48 | 25.4k | } |
<hashbrown::raw::inner::alloc::inner::Global as hashbrown::raw::inner::alloc::inner::Allocator>::allocate Line | Count | Source | 46 | 25.1k | fn allocate(&self, layout: Layout) -> Result<NonNull<u8>, ()> { | 47 | 25.1k | unsafe { NonNull::new(alloc(layout)).ok_or(()) } | 48 | 25.1k | } |
Unexecuted instantiation: <hashbrown::raw::inner::alloc::inner::Global as hashbrown::raw::inner::alloc::inner::Allocator>::allocate <hashbrown::raw::inner::alloc::inner::Global as hashbrown::raw::inner::alloc::inner::Allocator>::allocate Line | Count | Source | 46 | 3.38k | fn allocate(&self, layout: Layout) -> Result<NonNull<u8>, ()> { | 47 | 3.38k | unsafe { NonNull::new(alloc(layout)).ok_or(()) } | 48 | 3.38k | } |
Unexecuted instantiation: <hashbrown::raw::inner::alloc::inner::Global as hashbrown::raw::inner::alloc::inner::Allocator>::allocate Unexecuted instantiation: <hashbrown::raw::inner::alloc::inner::Global as hashbrown::raw::inner::alloc::inner::Allocator>::allocate Unexecuted instantiation: <hashbrown::raw::inner::alloc::inner::Global as hashbrown::raw::inner::alloc::inner::Allocator>::allocate <hashbrown::raw::inner::alloc::inner::Global as hashbrown::raw::inner::alloc::inner::Allocator>::allocate Line | Count | Source | 46 | 4.46k | fn allocate(&self, layout: Layout) -> Result<NonNull<u8>, ()> { | 47 | 4.46k | unsafe { NonNull::new(alloc(layout)).ok_or(()) } | 48 | 4.46k | } |
Unexecuted instantiation: <hashbrown::raw::inner::alloc::inner::Global as hashbrown::raw::inner::alloc::inner::Allocator>::allocate Unexecuted instantiation: <hashbrown::raw::inner::alloc::inner::Global as hashbrown::raw::inner::alloc::inner::Allocator>::allocate Unexecuted instantiation: <hashbrown::raw::inner::alloc::inner::Global as hashbrown::raw::inner::alloc::inner::Allocator>::allocate Unexecuted instantiation: <hashbrown::raw::inner::alloc::inner::Global as hashbrown::raw::inner::alloc::inner::Allocator>::allocate Unexecuted instantiation: <hashbrown::raw::inner::alloc::inner::Global as hashbrown::raw::inner::alloc::inner::Allocator>::allocate |
49 | | #[inline] |
50 | 87.1k | unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout) { |
51 | 87.1k | dealloc(ptr.as_ptr(), layout); |
52 | 87.1k | } <hashbrown::raw::inner::alloc::inner::Global as hashbrown::raw::inner::alloc::inner::Allocator>::deallocate Line | Count | Source | 50 | 264 | unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout) { | 51 | 264 | dealloc(ptr.as_ptr(), layout); | 52 | 264 | } |
Unexecuted instantiation: <hashbrown::raw::inner::alloc::inner::Global as hashbrown::raw::inner::alloc::inner::Allocator>::deallocate <hashbrown::raw::inner::alloc::inner::Global as hashbrown::raw::inner::alloc::inner::Allocator>::deallocate Line | Count | Source | 50 | 8.54k | unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout) { | 51 | 8.54k | dealloc(ptr.as_ptr(), layout); | 52 | 8.54k | } |
Unexecuted instantiation: <hashbrown::raw::inner::alloc::inner::Global as hashbrown::raw::inner::alloc::inner::Allocator>::deallocate Unexecuted instantiation: <hashbrown::raw::inner::alloc::inner::Global as hashbrown::raw::inner::alloc::inner::Allocator>::deallocate <hashbrown::raw::inner::alloc::inner::Global as hashbrown::raw::inner::alloc::inner::Allocator>::deallocate Line | Count | Source | 50 | 23.3k | unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout) { | 51 | 23.3k | dealloc(ptr.as_ptr(), layout); | 52 | 23.3k | } |
Unexecuted instantiation: <hashbrown::raw::inner::alloc::inner::Global as hashbrown::raw::inner::alloc::inner::Allocator>::deallocate <hashbrown::raw::inner::alloc::inner::Global as hashbrown::raw::inner::alloc::inner::Allocator>::deallocate Line | Count | Source | 50 | 25.1k | unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout) { | 51 | 25.1k | dealloc(ptr.as_ptr(), layout); | 52 | 25.1k | } |
Unexecuted instantiation: <hashbrown::raw::inner::alloc::inner::Global as hashbrown::raw::inner::alloc::inner::Allocator>::deallocate <hashbrown::raw::inner::alloc::inner::Global as hashbrown::raw::inner::alloc::inner::Allocator>::deallocate Line | Count | Source | 50 | 5.28k | unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout) { | 51 | 5.28k | dealloc(ptr.as_ptr(), layout); | 52 | 5.28k | } |
<hashbrown::raw::inner::alloc::inner::Global as hashbrown::raw::inner::alloc::inner::Allocator>::deallocate Line | Count | Source | 50 | 11.3k | unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout) { | 51 | 11.3k | dealloc(ptr.as_ptr(), layout); | 52 | 11.3k | } |
Unexecuted instantiation: <hashbrown::raw::inner::alloc::inner::Global as hashbrown::raw::inner::alloc::inner::Allocator>::deallocate Unexecuted instantiation: <hashbrown::raw::inner::alloc::inner::Global as hashbrown::raw::inner::alloc::inner::Allocator>::deallocate <hashbrown::raw::inner::alloc::inner::Global as hashbrown::raw::inner::alloc::inner::Allocator>::deallocate Line | Count | Source | 50 | 2.56k | unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout) { | 51 | 2.56k | dealloc(ptr.as_ptr(), layout); | 52 | 2.56k | } |
Unexecuted instantiation: <hashbrown::raw::inner::alloc::inner::Global as hashbrown::raw::inner::alloc::inner::Allocator>::deallocate Unexecuted instantiation: <hashbrown::raw::inner::alloc::inner::Global as hashbrown::raw::inner::alloc::inner::Allocator>::deallocate <hashbrown::raw::inner::alloc::inner::Global as hashbrown::raw::inner::alloc::inner::Allocator>::deallocate Line | Count | Source | 50 | 2.04k | unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout) { | 51 | 2.04k | dealloc(ptr.as_ptr(), layout); | 52 | 2.04k | } |
<hashbrown::raw::inner::alloc::inner::Global as hashbrown::raw::inner::alloc::inner::Allocator>::deallocate Line | Count | Source | 50 | 8.54k | unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout) { | 51 | 8.54k | dealloc(ptr.as_ptr(), layout); | 52 | 8.54k | } |
Unexecuted instantiation: <hashbrown::raw::inner::alloc::inner::Global as hashbrown::raw::inner::alloc::inner::Allocator>::deallocate Unexecuted instantiation: <hashbrown::raw::inner::alloc::inner::Global as hashbrown::raw::inner::alloc::inner::Allocator>::deallocate |
53 | | } |
54 | | impl Default for Global { |
55 | | #[inline] |
56 | | fn default() -> Self { |
57 | | Global |
58 | | } |
59 | | } |
60 | | |
61 | 87.1k | pub fn do_alloc<A: Allocator>(alloc: &A, layout: Layout) -> Result<NonNull<u8>, ()> { |
62 | 87.1k | alloc.allocate(layout) |
63 | 87.1k | } hashbrown::raw::inner::alloc::inner::do_alloc::<hashbrown::raw::inner::alloc::inner::Global> Line | Count | Source | 61 | 185 | pub fn do_alloc<A: Allocator>(alloc: &A, layout: Layout) -> Result<NonNull<u8>, ()> { | 62 | 185 | alloc.allocate(layout) | 63 | 185 | } |
Unexecuted instantiation: hashbrown::raw::inner::alloc::inner::do_alloc::<hashbrown::raw::inner::alloc::inner::Global> Unexecuted instantiation: hashbrown::raw::inner::alloc::inner::do_alloc::<hashbrown::raw::inner::alloc::inner::Global> Unexecuted instantiation: hashbrown::raw::inner::alloc::inner::do_alloc::<hashbrown::raw::inner::alloc::inner::Global> hashbrown::raw::inner::alloc::inner::do_alloc::<hashbrown::raw::inner::alloc::inner::Global> Line | Count | Source | 61 | 28.4k | pub fn do_alloc<A: Allocator>(alloc: &A, layout: Layout) -> Result<NonNull<u8>, ()> { | 62 | 28.4k | alloc.allocate(layout) | 63 | 28.4k | } |
hashbrown::raw::inner::alloc::inner::do_alloc::<hashbrown::raw::inner::alloc::inner::Global> Line | Count | Source | 61 | 25.4k | pub fn do_alloc<A: Allocator>(alloc: &A, layout: Layout) -> Result<NonNull<u8>, ()> { | 62 | 25.4k | alloc.allocate(layout) | 63 | 25.4k | } |
hashbrown::raw::inner::alloc::inner::do_alloc::<hashbrown::raw::inner::alloc::inner::Global> Line | Count | Source | 61 | 25.1k | pub fn do_alloc<A: Allocator>(alloc: &A, layout: Layout) -> Result<NonNull<u8>, ()> { | 62 | 25.1k | alloc.allocate(layout) | 63 | 25.1k | } |
Unexecuted instantiation: hashbrown::raw::inner::alloc::inner::do_alloc::<hashbrown::raw::inner::alloc::inner::Global> hashbrown::raw::inner::alloc::inner::do_alloc::<hashbrown::raw::inner::alloc::inner::Global> Line | Count | Source | 61 | 3.38k | pub fn do_alloc<A: Allocator>(alloc: &A, layout: Layout) -> Result<NonNull<u8>, ()> { | 62 | 3.38k | alloc.allocate(layout) | 63 | 3.38k | } |
Unexecuted instantiation: hashbrown::raw::inner::alloc::inner::do_alloc::<hashbrown::raw::inner::alloc::inner::Global> Unexecuted instantiation: hashbrown::raw::inner::alloc::inner::do_alloc::<hashbrown::raw::inner::alloc::inner::Global> Unexecuted instantiation: hashbrown::raw::inner::alloc::inner::do_alloc::<hashbrown::raw::inner::alloc::inner::Global> hashbrown::raw::inner::alloc::inner::do_alloc::<hashbrown::raw::inner::alloc::inner::Global> Line | Count | Source | 61 | 4.46k | pub fn do_alloc<A: Allocator>(alloc: &A, layout: Layout) -> Result<NonNull<u8>, ()> { | 62 | 4.46k | alloc.allocate(layout) | 63 | 4.46k | } |
Unexecuted instantiation: hashbrown::raw::inner::alloc::inner::do_alloc::<hashbrown::raw::inner::alloc::inner::Global> Unexecuted instantiation: hashbrown::raw::inner::alloc::inner::do_alloc::<hashbrown::raw::inner::alloc::inner::Global> Unexecuted instantiation: hashbrown::raw::inner::alloc::inner::do_alloc::<hashbrown::raw::inner::alloc::inner::Global> Unexecuted instantiation: hashbrown::raw::inner::alloc::inner::do_alloc::<hashbrown::raw::inner::alloc::inner::Global> Unexecuted instantiation: hashbrown::raw::inner::alloc::inner::do_alloc::<hashbrown::raw::inner::alloc::inner::Global> |
64 | | |
65 | | #[cfg(feature = "bumpalo")] |
66 | | unsafe impl Allocator for crate::BumpWrapper<'_> { |
67 | | #[allow(clippy::map_err_ignore)] |
68 | | fn allocate(&self, layout: Layout) -> Result<NonNull<u8>, ()> { |
69 | | self.0.try_alloc_layout(layout).map_err(|_| ()) |
70 | | } |
71 | | unsafe fn deallocate(&self, _ptr: NonNull<u8>, _layout: Layout) {} |
72 | | } |
73 | | } |