/rust/registry/src/index.crates.io-1949cf8c6b5b557f/alloc-stdlib-0.2.2/src/heap_alloc.rs
Line | Count | Source |
1 | | use std; |
2 | | |
3 | | |
4 | | use super::{SliceWrapper, SliceWrapperMut, Allocator}; |
5 | | |
6 | | use std::ops; |
7 | | use std::ops::Range; |
8 | | use std::boxed::Box; |
9 | | use std::vec::Vec; |
10 | | pub struct WrapBox<T>(std::boxed::Box<[T]>); |
11 | | |
12 | | impl<T> From<Vec<T>> for WrapBox<T> { |
13 | 719k | fn from(data: Vec<T>) -> Self { |
14 | 719k | WrapBox(data.into_boxed_slice()) |
15 | 719k | } Unexecuted instantiation: <alloc_stdlib::heap_alloc::WrapBox<brotli_decompressor::huffman::HuffmanCode> as core::convert::From<alloc::vec::Vec<brotli_decompressor::huffman::HuffmanCode>>>::from Unexecuted instantiation: <alloc_stdlib::heap_alloc::WrapBox<u8> as core::convert::From<alloc::vec::Vec<u8>>>::from Unexecuted instantiation: <alloc_stdlib::heap_alloc::WrapBox<u32> as core::convert::From<alloc::vec::Vec<u32>>>::from Unexecuted instantiation: <alloc_stdlib::heap_alloc::WrapBox<brotli_decompressor::huffman::HuffmanCode> as core::convert::From<alloc::vec::Vec<brotli_decompressor::huffman::HuffmanCode>>>::from Unexecuted instantiation: <alloc_stdlib::heap_alloc::WrapBox<u8> as core::convert::From<alloc::vec::Vec<u8>>>::from Unexecuted instantiation: <alloc_stdlib::heap_alloc::WrapBox<u32> as core::convert::From<alloc::vec::Vec<u32>>>::from Unexecuted instantiation: <alloc_stdlib::heap_alloc::WrapBox<brotli_decompressor::huffman::HuffmanCode> as core::convert::From<alloc::vec::Vec<brotli_decompressor::huffman::HuffmanCode>>>::from Unexecuted instantiation: <alloc_stdlib::heap_alloc::WrapBox<u8> as core::convert::From<alloc::vec::Vec<u8>>>::from Unexecuted instantiation: <alloc_stdlib::heap_alloc::WrapBox<u32> as core::convert::From<alloc::vec::Vec<u32>>>::from <alloc_stdlib::heap_alloc::WrapBox<brotli_decompressor::huffman::HuffmanCode> as core::convert::From<alloc::vec::Vec<brotli_decompressor::huffman::HuffmanCode>>>::from Line | Count | Source | 13 | 116k | fn from(data: Vec<T>) -> Self { | 14 | 116k | WrapBox(data.into_boxed_slice()) | 15 | 116k | } |
<alloc_stdlib::heap_alloc::WrapBox<u8> as core::convert::From<alloc::vec::Vec<u8>>>::from Line | Count | Source | 13 | 98.1k | fn from(data: Vec<T>) -> Self { | 14 | 98.1k | WrapBox(data.into_boxed_slice()) | 15 | 98.1k | } |
<alloc_stdlib::heap_alloc::WrapBox<u32> as core::convert::From<alloc::vec::Vec<u32>>>::from Line | Count | Source | 13 | 45.7k | fn from(data: Vec<T>) -> Self { | 14 | 45.7k | WrapBox(data.into_boxed_slice()) | 15 | 45.7k | } |
<alloc_stdlib::heap_alloc::WrapBox<brotli_decompressor::huffman::HuffmanCode> as core::convert::From<alloc::vec::Vec<brotli_decompressor::huffman::HuffmanCode>>>::from Line | Count | Source | 13 | 208k | fn from(data: Vec<T>) -> Self { | 14 | 208k | WrapBox(data.into_boxed_slice()) | 15 | 208k | } |
<alloc_stdlib::heap_alloc::WrapBox<u8> as core::convert::From<alloc::vec::Vec<u8>>>::from Line | Count | Source | 13 | 173k | fn from(data: Vec<T>) -> Self { | 14 | 173k | WrapBox(data.into_boxed_slice()) | 15 | 173k | } |
<alloc_stdlib::heap_alloc::WrapBox<u32> as core::convert::From<alloc::vec::Vec<u32>>>::from Line | Count | Source | 13 | 77.2k | fn from(data: Vec<T>) -> Self { | 14 | 77.2k | WrapBox(data.into_boxed_slice()) | 15 | 77.2k | } |
|
16 | | } |
17 | | |
18 | | impl<T> Into<Box<[T]>> for WrapBox<T> { |
19 | | fn into(self) -> Box<[T]> { |
20 | | self.0 |
21 | | } |
22 | | } |
23 | | |
24 | | impl<T> Default for WrapBox<T> { |
25 | 11.9M | fn default() -> Self { |
26 | 11.9M | let v : std::vec::Vec<T> = std::vec::Vec::new(); |
27 | 11.9M | let b = v.into_boxed_slice(); |
28 | 11.9M | return WrapBox::<T>(b); |
29 | 11.9M | } Unexecuted instantiation: <alloc_stdlib::heap_alloc::WrapBox<brotli_decompressor::huffman::HuffmanCode> as core::default::Default>::default Unexecuted instantiation: <alloc_stdlib::heap_alloc::WrapBox<u32> as core::default::Default>::default Unexecuted instantiation: <alloc_stdlib::heap_alloc::WrapBox<u8> as core::default::Default>::default Unexecuted instantiation: <alloc_stdlib::heap_alloc::WrapBox<u8> as core::default::Default>::default Unexecuted instantiation: <alloc_stdlib::heap_alloc::WrapBox<brotli_decompressor::huffman::HuffmanCode> as core::default::Default>::default Unexecuted instantiation: <alloc_stdlib::heap_alloc::WrapBox<u32> as core::default::Default>::default Unexecuted instantiation: <alloc_stdlib::heap_alloc::WrapBox<brotli_decompressor::huffman::HuffmanCode> as core::default::Default>::default Unexecuted instantiation: <alloc_stdlib::heap_alloc::WrapBox<u8> as core::default::Default>::default Unexecuted instantiation: <alloc_stdlib::heap_alloc::WrapBox<u32> as core::default::Default>::default <alloc_stdlib::heap_alloc::WrapBox<u8> as core::default::Default>::default Line | Count | Source | 25 | 457k | fn default() -> Self { | 26 | 457k | let v : std::vec::Vec<T> = std::vec::Vec::new(); | 27 | 457k | let b = v.into_boxed_slice(); | 28 | 457k | return WrapBox::<T>(b); | 29 | 457k | } |
<alloc_stdlib::heap_alloc::WrapBox<brotli_decompressor::huffman::HuffmanCode> as core::default::Default>::default Line | Count | Source | 25 | 3.25M | fn default() -> Self { | 26 | 3.25M | let v : std::vec::Vec<T> = std::vec::Vec::new(); | 27 | 3.25M | let b = v.into_boxed_slice(); | 28 | 3.25M | return WrapBox::<T>(b); | 29 | 3.25M | } |
<alloc_stdlib::heap_alloc::WrapBox<u32> as core::default::Default>::default Line | Count | Source | 25 | 3.05M | fn default() -> Self { | 26 | 3.05M | let v : std::vec::Vec<T> = std::vec::Vec::new(); | 27 | 3.05M | let b = v.into_boxed_slice(); | 28 | 3.05M | return WrapBox::<T>(b); | 29 | 3.05M | } |
<alloc_stdlib::heap_alloc::WrapBox<u8> as core::default::Default>::default Line | Count | Source | 25 | 977k | fn default() -> Self { | 26 | 977k | let v : std::vec::Vec<T> = std::vec::Vec::new(); | 27 | 977k | let b = v.into_boxed_slice(); | 28 | 977k | return WrapBox::<T>(b); | 29 | 977k | } |
<alloc_stdlib::heap_alloc::WrapBox<brotli_decompressor::huffman::HuffmanCode> as core::default::Default>::default Line | Count | Source | 25 | 2.29M | fn default() -> Self { | 26 | 2.29M | let v : std::vec::Vec<T> = std::vec::Vec::new(); | 27 | 2.29M | let b = v.into_boxed_slice(); | 28 | 2.29M | return WrapBox::<T>(b); | 29 | 2.29M | } |
<alloc_stdlib::heap_alloc::WrapBox<u32> as core::default::Default>::default Line | Count | Source | 25 | 1.92M | fn default() -> Self { | 26 | 1.92M | let v : std::vec::Vec<T> = std::vec::Vec::new(); | 27 | 1.92M | let b = v.into_boxed_slice(); | 28 | 1.92M | return WrapBox::<T>(b); | 29 | 1.92M | } |
|
30 | | } |
31 | | |
32 | | impl<T> super::SliceWrapper<T> for WrapBox<T> { |
33 | 2.39G | fn slice(&self) -> & [T] { |
34 | 2.39G | return &*self.0 |
35 | 2.39G | } Unexecuted instantiation: <alloc_stdlib::heap_alloc::WrapBox<u32> as alloc_no_stdlib::allocated_memory::SliceWrapper<u32>>::slice Unexecuted instantiation: <alloc_stdlib::heap_alloc::WrapBox<brotli_decompressor::huffman::HuffmanCode> as alloc_no_stdlib::allocated_memory::SliceWrapper<brotli_decompressor::huffman::HuffmanCode>>::slice Unexecuted instantiation: <alloc_stdlib::heap_alloc::WrapBox<u8> as alloc_no_stdlib::allocated_memory::SliceWrapper<u8>>::slice Unexecuted instantiation: <alloc_stdlib::heap_alloc::WrapBox<brotli_decompressor::huffman::HuffmanCode> as alloc_no_stdlib::allocated_memory::SliceWrapper<brotli_decompressor::huffman::HuffmanCode>>::slice Unexecuted instantiation: <alloc_stdlib::heap_alloc::WrapBox<u8> as alloc_no_stdlib::allocated_memory::SliceWrapper<u8>>::slice Unexecuted instantiation: <alloc_stdlib::heap_alloc::WrapBox<u32> as alloc_no_stdlib::allocated_memory::SliceWrapper<u32>>::slice Unexecuted instantiation: <alloc_stdlib::heap_alloc::WrapBox<brotli_decompressor::huffman::HuffmanCode> as alloc_no_stdlib::allocated_memory::SliceWrapper<brotli_decompressor::huffman::HuffmanCode>>::slice Unexecuted instantiation: <alloc_stdlib::heap_alloc::WrapBox<u8> as alloc_no_stdlib::allocated_memory::SliceWrapper<u8>>::slice Unexecuted instantiation: <alloc_stdlib::heap_alloc::WrapBox<u32> as alloc_no_stdlib::allocated_memory::SliceWrapper<u32>>::slice <alloc_stdlib::heap_alloc::WrapBox<u32> as alloc_no_stdlib::allocated_memory::SliceWrapper<u32>>::slice Line | Count | Source | 33 | 1.32M | fn slice(&self) -> & [T] { | 34 | 1.32M | return &*self.0 | 35 | 1.32M | } |
<alloc_stdlib::heap_alloc::WrapBox<brotli_decompressor::huffman::HuffmanCode> as alloc_no_stdlib::allocated_memory::SliceWrapper<brotli_decompressor::huffman::HuffmanCode>>::slice Line | Count | Source | 33 | 3.20M | fn slice(&self) -> & [T] { | 34 | 3.20M | return &*self.0 | 35 | 3.20M | } |
<alloc_stdlib::heap_alloc::WrapBox<u8> as alloc_no_stdlib::allocated_memory::SliceWrapper<u8>>::slice Line | Count | Source | 33 | 1.20G | fn slice(&self) -> & [T] { | 34 | 1.20G | return &*self.0 | 35 | 1.20G | } |
<alloc_stdlib::heap_alloc::WrapBox<u32> as alloc_no_stdlib::allocated_memory::SliceWrapper<u32>>::slice Line | Count | Source | 33 | 514k | fn slice(&self) -> & [T] { | 34 | 514k | return &*self.0 | 35 | 514k | } |
<alloc_stdlib::heap_alloc::WrapBox<brotli_decompressor::huffman::HuffmanCode> as alloc_no_stdlib::allocated_memory::SliceWrapper<brotli_decompressor::huffman::HuffmanCode>>::slice Line | Count | Source | 33 | 14.0M | fn slice(&self) -> & [T] { | 34 | 14.0M | return &*self.0 | 35 | 14.0M | } |
<alloc_stdlib::heap_alloc::WrapBox<u8> as alloc_no_stdlib::allocated_memory::SliceWrapper<u8>>::slice Line | Count | Source | 33 | 1.17G | fn slice(&self) -> & [T] { | 34 | 1.17G | return &*self.0 | 35 | 1.17G | } |
|
36 | | } |
37 | | |
38 | | impl<T> super::SliceWrapperMut<T> for WrapBox<T> { |
39 | 2.99G | fn slice_mut(&mut self) -> &mut [T] { |
40 | 2.99G | return &mut*self.0 |
41 | 2.99G | } Unexecuted instantiation: <alloc_stdlib::heap_alloc::WrapBox<brotli_decompressor::huffman::HuffmanCode> as alloc_no_stdlib::allocated_memory::SliceWrapperMut<brotli_decompressor::huffman::HuffmanCode>>::slice_mut Unexecuted instantiation: <alloc_stdlib::heap_alloc::WrapBox<u32> as alloc_no_stdlib::allocated_memory::SliceWrapperMut<u32>>::slice_mut Unexecuted instantiation: <alloc_stdlib::heap_alloc::WrapBox<u8> as alloc_no_stdlib::allocated_memory::SliceWrapperMut<u8>>::slice_mut Unexecuted instantiation: <alloc_stdlib::heap_alloc::WrapBox<brotli_decompressor::huffman::HuffmanCode> as alloc_no_stdlib::allocated_memory::SliceWrapperMut<brotli_decompressor::huffman::HuffmanCode>>::slice_mut Unexecuted instantiation: <alloc_stdlib::heap_alloc::WrapBox<u8> as alloc_no_stdlib::allocated_memory::SliceWrapperMut<u8>>::slice_mut Unexecuted instantiation: <alloc_stdlib::heap_alloc::WrapBox<u32> as alloc_no_stdlib::allocated_memory::SliceWrapperMut<u32>>::slice_mut Unexecuted instantiation: <alloc_stdlib::heap_alloc::WrapBox<brotli_decompressor::huffman::HuffmanCode> as alloc_no_stdlib::allocated_memory::SliceWrapperMut<brotli_decompressor::huffman::HuffmanCode>>::slice_mut Unexecuted instantiation: <alloc_stdlib::heap_alloc::WrapBox<u8> as alloc_no_stdlib::allocated_memory::SliceWrapperMut<u8>>::slice_mut Unexecuted instantiation: <alloc_stdlib::heap_alloc::WrapBox<u32> as alloc_no_stdlib::allocated_memory::SliceWrapperMut<u32>>::slice_mut <alloc_stdlib::heap_alloc::WrapBox<u8> as alloc_no_stdlib::allocated_memory::SliceWrapperMut<u8>>::slice_mut Line | Count | Source | 39 | 1.41G | fn slice_mut(&mut self) -> &mut [T] { | 40 | 1.41G | return &mut*self.0 | 41 | 1.41G | } |
<alloc_stdlib::heap_alloc::WrapBox<brotli_decompressor::huffman::HuffmanCode> as alloc_no_stdlib::allocated_memory::SliceWrapperMut<brotli_decompressor::huffman::HuffmanCode>>::slice_mut Line | Count | Source | 39 | 95.2k | fn slice_mut(&mut self) -> &mut [T] { | 40 | 95.2k | return &mut*self.0 | 41 | 95.2k | } |
<alloc_stdlib::heap_alloc::WrapBox<u32> as alloc_no_stdlib::allocated_memory::SliceWrapperMut<u32>>::slice_mut Line | Count | Source | 39 | 39.5k | fn slice_mut(&mut self) -> &mut [T] { | 40 | 39.5k | return &mut*self.0 | 41 | 39.5k | } |
<alloc_stdlib::heap_alloc::WrapBox<brotli_decompressor::huffman::HuffmanCode> as alloc_no_stdlib::allocated_memory::SliceWrapperMut<brotli_decompressor::huffman::HuffmanCode>>::slice_mut Line | Count | Source | 39 | 187k | fn slice_mut(&mut self) -> &mut [T] { | 40 | 187k | return &mut*self.0 | 41 | 187k | } |
<alloc_stdlib::heap_alloc::WrapBox<u8> as alloc_no_stdlib::allocated_memory::SliceWrapperMut<u8>>::slice_mut Line | Count | Source | 39 | 1.58G | fn slice_mut(&mut self) -> &mut [T] { | 40 | 1.58G | return &mut*self.0 | 41 | 1.58G | } |
<alloc_stdlib::heap_alloc::WrapBox<u32> as alloc_no_stdlib::allocated_memory::SliceWrapperMut<u32>>::slice_mut Line | Count | Source | 39 | 96.1k | fn slice_mut(&mut self) -> &mut [T] { | 40 | 96.1k | return &mut*self.0 | 41 | 96.1k | } |
|
42 | | } |
43 | | impl<T> ops::Index<usize> for WrapBox<T> { |
44 | | type Output = T; |
45 | | fn index(&self, index: usize) -> &T { |
46 | | &(*self.0)[index] |
47 | | } |
48 | | } |
49 | | |
50 | | impl<T> ops::IndexMut<usize> for WrapBox<T> { |
51 | | fn index_mut(&mut self, index: usize) -> &mut T { |
52 | | &mut (*self.0)[index] |
53 | | } |
54 | | } |
55 | | |
56 | | impl<T> ops::Index<Range<usize>> for WrapBox<T> { |
57 | | type Output = [T]; |
58 | | fn index(&self, index: Range<usize>) -> &[T] { |
59 | | &(*self.0)[index] |
60 | | } |
61 | | } |
62 | | |
63 | | impl<T> ops::IndexMut<Range<usize>> for WrapBox<T> { |
64 | | fn index_mut(&mut self, index: Range<usize>) -> &mut [T] { |
65 | | &mut (*self.0)[index] |
66 | | } |
67 | | } |
68 | | |
69 | | |
70 | | pub struct HeapAlloc<T : Clone>{ |
71 | | pub default_value : T, |
72 | | } |
73 | | |
74 | | impl<T: Clone+Default> Default for HeapAlloc<T> { |
75 | | fn default() -> Self { |
76 | | Self::new(T::default()) |
77 | | } |
78 | | } |
79 | | |
80 | | impl<T : Clone> HeapAlloc<T> { |
81 | | pub fn new(data : T) -> HeapAlloc<T> { |
82 | | return HeapAlloc::<T>{default_value : data}; |
83 | | } |
84 | | } |
85 | | |
86 | | impl<T : Clone> super::Allocator<T> for HeapAlloc<T> { |
87 | | type AllocatedMemory = WrapBox<T>; |
88 | | fn alloc_cell(self : &mut HeapAlloc<T>, len : usize) -> WrapBox<T> { |
89 | | |
90 | | let v : std::vec::Vec<T> = vec![self.default_value.clone();len]; |
91 | | let b = v.into_boxed_slice(); |
92 | | return WrapBox::<T>(b); |
93 | | } |
94 | | fn free_cell(self : &mut HeapAlloc<T>, _data : WrapBox<T>) { |
95 | | |
96 | | } |
97 | | } |
98 | | |
99 | | #[deprecated] |
100 | | pub type HeapAllocUninitialized<T> = HeapAlloc<T>; |
101 | | |
102 | | |
103 | | pub struct HeapPrealloc<'a, T : 'a> { |
104 | | freelist : std::boxed::Box<[&'a mut [T]]>, |
105 | | } |
106 | | define_stack_allocator_traits!(HeapPrealloc, heap); |
107 | | |
108 | | impl<'a, T : Clone+'a> HeapPrealloc<'a, T> { |
109 | | fn make_freelist(freelist_size : usize) -> std::boxed::Box<[&'a mut[T]]> { |
110 | | let mut retval = Vec::<&'a mut[T]>::with_capacity(freelist_size); |
111 | | for _i in 0..freelist_size { |
112 | | retval.push(&mut[]); |
113 | | } |
114 | | return retval.into_boxed_slice(); |
115 | | } |
116 | | pub fn new_allocator(freelist_size : usize, |
117 | | memory_pool : &'a mut Box<[T]>, |
118 | | initializer : fn(&mut[T])) -> super::StackAllocator<'a, T, HeapPrealloc<'a, T> > { |
119 | | let mut retval = super::StackAllocator::<T, HeapPrealloc<T> > { |
120 | | nop : &mut [], |
121 | | system_resources : HeapPrealloc::<T> { |
122 | | freelist : Self::make_freelist(freelist_size), |
123 | | }, |
124 | | free_list_start : freelist_size, |
125 | | free_list_overflow_count : 0, |
126 | | initialize : initializer, |
127 | | }; |
128 | | retval.free_cell(super::AllocatedStackMemory::<T>{mem:&mut*memory_pool}); |
129 | | return retval; |
130 | | } |
131 | | #[cfg(feature="unsafe")] |
132 | | pub unsafe fn new_uninitialized_memory_pool(len : usize) -> Box<[T]> { |
133 | | let mut v : std::vec::Vec<T> = std::vec::Vec::with_capacity(len); |
134 | | v.set_len(len); |
135 | | return v.into_boxed_slice(); |
136 | | } |
137 | | } |
138 | | |