1
1
//! Provides types for dealing with CQL value deserialization.
2
2
3
+ use bytes:: Bytes ;
3
4
use std:: {
4
5
collections:: { BTreeMap , BTreeSet , HashMap , HashSet } ,
5
6
hash:: { BuildHasher , Hash } ,
6
7
net:: IpAddr ,
7
8
} ;
8
-
9
- use bytes:: Bytes ;
10
9
use uuid:: Uuid ;
11
10
12
11
use std:: fmt:: { Display , Pointer } ;
@@ -759,7 +758,7 @@ pub struct VectorIterator<'frame, T> {
759
758
}
760
759
761
760
impl < ' frame , T > VectorIterator < ' frame , T > {
762
- fn new (
761
+ pub fn new (
763
762
coll_typ : & ' frame ColumnType ,
764
763
elem_typ : & ' frame ColumnType ,
765
764
count : usize ,
@@ -774,6 +773,25 @@ impl<'frame, T> VectorIterator<'frame, T> {
774
773
phantom_data : std:: marker:: PhantomData ,
775
774
}
776
775
}
776
+
777
+ /// Faster specialization for deserializing a `vector<float>` into `Vec<CqlValue>`.
778
+ /// The generic code `Vec<CqlValue>::deserialize(...)` is much slower because it has to
779
+ /// match on the element type for every item in the vector.
780
+ /// Here we just hardcode `f32` and we can shortcut a lot of code.
781
+ ///
782
+ /// This could be nicer if Rust had generic type specialization in stable,
783
+ /// but for now we need a separate method.
784
+ pub fn deserialize_vector_of_float_to_vec_of_cql_value (
785
+ typ : & ' frame ColumnType ,
786
+ v : Option < FrameSlice < ' frame > > ,
787
+ ) -> Result < Vec < CqlValue > , DeserializationError > {
788
+ VectorIterator :: < ' frame , f32 > :: deserialize ( typ, v)
789
+ . and_then ( |it| {
790
+ it. map ( |e| e. map ( CqlValue :: Float ) )
791
+ . collect :: < Result < Vec < CqlValue > , DeserializationError > > ( )
792
+ } )
793
+ . map_err ( deser_error_replace_rust_name :: < Self > )
794
+ }
777
795
}
778
796
779
797
impl < ' frame , T > DeserializeValue < ' frame > for VectorIterator < ' frame , T >
@@ -828,6 +846,7 @@ where
828
846
{
829
847
type Item = Result < T , DeserializationError > ;
830
848
849
+ #[ inline]
831
850
fn next ( & mut self ) -> Option < Self :: Item > {
832
851
let raw = self . raw_iter . next ( ) ?. map_err ( |err| {
833
852
mk_deser_err :: < Self > (
@@ -883,6 +902,7 @@ where
883
902
. and_then ( |it| it. collect :: < Result < _ , DeserializationError > > ( ) )
884
903
. map_err ( deser_error_replace_rust_name :: < Self > )
885
904
}
905
+
886
906
ColumnType :: Vector ( _, _) => VectorIterator :: < ' frame , T > :: deserialize ( typ, v)
887
907
. and_then ( |it| it. collect :: < Result < _ , DeserializationError > > ( ) )
888
908
. map_err ( deser_error_replace_rust_name :: < Self > ) ,
@@ -1435,6 +1455,7 @@ impl<'frame> VectorBytesSequenceIterator<'frame> {
1435
1455
impl < ' frame > Iterator for VectorBytesSequenceIterator < ' frame > {
1436
1456
type Item = Result < Option < FrameSlice < ' frame > > , LowLevelDeserializationError > ;
1437
1457
1458
+ #[ inline]
1438
1459
fn next ( & mut self ) -> Option < Self :: Item > {
1439
1460
self . remaining = self . remaining . checked_sub ( 1 ) ?;
1440
1461
Some ( self . slice . read_subslice ( self . elem_len ) )
0 commit comments