@@ -83,7 +83,7 @@ impl KeyCache {
8383
8484 /// Returns the `value` property name.
8585 pub ( super ) fn value < ' s > ( & mut self , scope : & mut HandleScope < ' s > ) -> Local < ' s , v8:: String > {
86- Self :: get_or_create_key ( scope, & mut self . tag , "value" )
86+ Self :: get_or_create_key ( scope, & mut self . value , "value" )
8787 }
8888
8989 /// Returns an interned string corresponding to `string`
@@ -256,6 +256,8 @@ impl<'de, 'a, 's: 'de> de::Deserializer<'de> for Deserializer<'a, 's> {
256256 }
257257}
258258
259+ /// Provides access to the field names and values in a JS object
260+ /// under the assumption that it's a product.
259261struct ProductAccess < ' a , ' s > {
260262 common : DeserializerCommon < ' a , ' s > ,
261263 /// The input object being deserialized.
@@ -266,10 +268,6 @@ struct ProductAccess<'a, 's> {
266268 index : usize ,
267269}
268270
269- /// Map from integer keys to their `str` representation,
270- /// for small numbers up to 12.
271- static INT_TO_STR : & [ & str ] = & [ "0" , "1" , "2" , "3" , "4" , "5" , "6" , "7" , "8" , "9" , "10" , "11" , "12" ] ;
272-
273271impl < ' de , ' s : ' de > de:: NamedProductAccess < ' de > for ProductAccess < ' _ , ' s > {
274272 type Error = Error < ' s > ;
275273
@@ -284,16 +282,13 @@ impl<'de, 's: 'de> de::NamedProductAccess<'de> for ProductAccess<'_, 's> {
284282 // Normalize the field name.
285283 // Integer keys are converted to strings,
286284 // as that is supported on JS objects.
287- // TODO(centril, perf): consider replacing this with `itoa::Buffer`.
288- let mut string_mem = None ;
289285 let field = match field {
290- Some ( field) => field,
291- None if index <= 12 => INT_TO_STR [ index] ,
292- None => string_mem. insert ( format ! ( "{index}" ) ) ,
286+ Some ( field) => Cow :: Borrowed ( field) ,
287+ None => Cow :: Owned ( format ! ( "{index}" ) ) ,
293288 } ;
294289
295290 // Check that such a field/key exists.
296- let key = v8_interned_string ( scope, field) . into ( ) ;
291+ let key = v8_interned_string ( scope, & field) . into ( ) ;
297292 if !self
298293 . object
299294 . has_own_property ( scope, key)
@@ -328,6 +323,8 @@ impl<'de, 's: 'de> de::NamedProductAccess<'de> for ProductAccess<'_, 's> {
328323 }
329324}
330325
326+ /// Used in `Deserializer::deserialize_sum` to translate a `tag` property of a JS object
327+ /// to a variant and to provide a deserializer for its value/payload.
331328struct SumAccess < ' a , ' s > {
332329 common : DeserializerCommon < ' a , ' s > ,
333330 /// The tag of the sum value.
@@ -368,6 +365,8 @@ impl<'de, 'a, 's: 'de> de::VariantAccess<'de> for Deserializer<'a, 's> {
368365 }
369366}
370367
368+ /// Used by an `ArrayVisitor` to deserialize every element of a JS array
369+ /// to a SATS array.
371370struct ArrayAccess < ' a , ' s , T > {
372371 common : DeserializerCommon < ' a , ' s > ,
373372 arr : Local < ' s , Array > ,
0 commit comments