File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed
Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -3,17 +3,22 @@ use std::hash::{BuildHasher, Hash};
33
44/// The trait required to be able to use a type in `BytePool`.
55pub trait Poolable {
6+ fn len ( & self ) -> usize ;
67 fn capacity ( & self ) -> usize ;
78 fn alloc ( size : usize ) -> Self ;
89}
910
1011impl < T : Default + Clone > Poolable for Vec < T > {
11- fn capacity ( & self ) -> usize {
12+ fn len ( & self ) -> usize {
1213 self . len ( )
1314 }
1415
16+ fn capacity ( & self ) -> usize {
17+ self . capacity ( )
18+ }
19+
1520 fn alloc ( size : usize ) -> Self {
16- vec ! [ T :: default ( ) ; size]
21+ Vec :: < T > :: with_capacity ( size)
1722 }
1823}
1924
@@ -22,10 +27,14 @@ where
2227 K : Eq + Hash ,
2328 S : BuildHasher + Default ,
2429{
25- fn capacity ( & self ) -> usize {
30+ fn len ( & self ) -> usize {
2631 self . len ( )
2732 }
2833
34+ fn capacity ( & self ) -> usize {
35+ self . capacity ( )
36+ }
37+
2938 fn alloc ( size : usize ) -> Self {
3039 HashMap :: with_capacity_and_hasher ( size, Default :: default ( ) )
3140 }
You can’t perform that action at this time.
0 commit comments