@@ -79,29 +79,29 @@ struct GuardedNullableGc<Val: 'static> {
79
79
impl < Val : ' static > GuardedNullableGc < Val > {
80
80
/// Creates a garbage collectible value to the given reference.
81
81
///
82
- /// SAFETY; the caller must ensure that the guard is dropped before the value is dropped.
83
- fn r#ref ( val : & Val ) -> ( Self , GcGuard < ' _ , Val > ) {
82
+ /// # Safety
83
+ ///
84
+ /// The caller must ensure that the guard is dropped before the value is dropped.
85
+ fn new_ref ( val : & Val ) -> ( Self , GcGuard < ' _ , Val > ) {
84
86
Self :: new ( Guarded :: Ref ( val) )
85
87
}
86
88
87
89
/// Creates a garbage collectible value to the given reference.
88
90
///
89
- /// SAFETY; the caller must ensure that the guard is dropped before the value is dropped.
90
- fn r#owned < ' a > ( val : Val ) -> ( Self , GcGuard < ' a , Val > ) {
91
+ /// # Safety
92
+ ///
93
+ /// The caller must ensure that the guard is dropped before the value is dropped.
94
+ fn new_owned < ' a > ( val : Val ) -> ( Self , GcGuard < ' a , Val > ) {
91
95
Self :: new ( Guarded :: Owned ( val) )
92
96
}
93
97
94
98
fn new ( val : Guarded < ' _ , Val > ) -> ( Self , GcGuard < ' _ , Val > ) {
95
99
let inner = Rc :: new ( RefCell :: new ( Some ( val) ) ) ;
96
100
let guard = GcGuard { inner : Rc :: clone ( & inner) } ;
97
101
98
- // SAFETY: guard enforces that the value is removed from the refcell before it is dropped
99
- let this = Self {
100
- inner : unsafe {
101
- #[ allow( clippy:: missing_transmute_annotations) ]
102
- std:: mem:: transmute ( inner)
103
- } ,
104
- } ;
102
+ // SAFETY: guard enforces that the value is removed from the refcell before it is dropped.
103
+ #[ allow( clippy:: missing_transmute_annotations) ]
104
+ let this = Self { inner : unsafe { std:: mem:: transmute ( inner) } } ;
105
105
106
106
( this, guard)
107
107
}
@@ -111,10 +111,7 @@ impl<Val: 'static> GuardedNullableGc<Val> {
111
111
where
112
112
F : FnOnce ( & Val ) -> R ,
113
113
{
114
- self . inner . borrow ( ) . as_ref ( ) . map ( |val| match val {
115
- Guarded :: Ref ( val) => f ( val) ,
116
- Guarded :: Owned ( val) => f ( val) ,
117
- } )
114
+ self . inner . borrow ( ) . as_ref ( ) . map ( |guard| f ( guard. as_ref ( ) ) )
118
115
}
119
116
}
120
117
@@ -131,6 +128,16 @@ enum Guarded<'a, T> {
131
128
Owned ( T ) ,
132
129
}
133
130
131
+ impl < T > Guarded < ' _ , T > {
132
+ #[ inline]
133
+ fn as_ref ( & self ) -> & T {
134
+ match self {
135
+ Guarded :: Ref ( val) => val,
136
+ Guarded :: Owned ( val) => val,
137
+ }
138
+ }
139
+ }
140
+
134
141
/// Guard the inner value, once this value is dropped the inner value is also removed.
135
142
///
136
143
/// This type guarantees that it never outlives the wrapped value.
@@ -232,7 +239,7 @@ pub(crate) struct MemoryRef(GuardedNullableGc<SharedMemory>);
232
239
impl MemoryRef {
233
240
/// Creates a new stack reference
234
241
pub ( crate ) fn new ( mem : & SharedMemory ) -> ( Self , GcGuard < ' _ , SharedMemory > ) {
235
- let ( inner, guard) = GuardedNullableGc :: r#ref ( mem) ;
242
+ let ( inner, guard) = GuardedNullableGc :: new_ref ( mem) ;
236
243
( Self ( inner) , guard)
237
244
}
238
245
@@ -324,7 +331,7 @@ pub(crate) struct StateRef(GuardedNullableGc<State>);
324
331
impl StateRef {
325
332
/// Creates a new stack reference
326
333
pub ( crate ) fn new ( state : & State ) -> ( Self , GcGuard < ' _ , State > ) {
327
- let ( inner, guard) = GuardedNullableGc :: r#ref ( state) ;
334
+ let ( inner, guard) = GuardedNullableGc :: new_ref ( state) ;
328
335
( Self ( inner) , guard)
329
336
}
330
337
@@ -349,7 +356,7 @@ where
349
356
{
350
357
/// Creates a new stack reference
351
358
fn new < ' a > ( db : DB ) -> ( Self , GcGuard < ' a , DB > ) {
352
- let ( inner, guard) = GuardedNullableGc :: owned ( db) ;
359
+ let ( inner, guard) = GuardedNullableGc :: new_owned ( db) ;
353
360
( Self ( inner) , guard)
354
361
}
355
362
}
@@ -417,7 +424,7 @@ pub(crate) struct StackRef(GuardedNullableGc<Stack>);
417
424
impl StackRef {
418
425
/// Creates a new stack reference
419
426
pub ( crate ) fn new ( stack : & Stack ) -> ( Self , GcGuard < ' _ , Stack > ) {
420
- let ( inner, guard) = GuardedNullableGc :: r#ref ( stack) ;
427
+ let ( inner, guard) = GuardedNullableGc :: new_ref ( stack) ;
421
428
( Self ( inner) , guard)
422
429
}
423
430
@@ -790,19 +797,15 @@ impl EvmDbRef {
790
797
return JsArrayBuffer :: new ( 0 , ctx) ;
791
798
}
792
799
793
- let Some ( Ok ( code) ) = self
794
- . inner
795
- . db
796
- . 0
797
- . with_inner ( |db| db. code_by_hash_ref ( code_hash) . map ( |code| code. bytecode_bytes ( ) ) )
800
+ let Some ( Ok ( bytecode) ) = self . inner . db . 0 . with_inner ( |db| db. code_by_hash_ref ( code_hash) )
798
801
else {
799
802
return Err ( JsError :: from_native (
800
803
JsNativeError :: error ( )
801
- . with_message ( format ! ( "Failed to read code hash {code_hash:?} from database" , ) ) ,
804
+ . with_message ( format ! ( "Failed to read code hash {code_hash:?} from database" ) ) ,
802
805
) ) ;
803
806
} ;
804
807
805
- to_buf ( code . into ( ) , ctx)
808
+ to_buf ( bytecode . bytes ( ) . to_vec ( ) , ctx)
806
809
}
807
810
808
811
fn read_state (
0 commit comments