@@ -8,7 +8,7 @@ use vortex_mask::Mask;
88
99use crate :: { StructVectorMut , Vector , VectorMutOps , VectorOps } ;
1010
11- /// An immutable vector of boolean values.
11+ /// An immutable vector of struct values.
1212///
1313/// `StructVector` can be considered a borrowed / frozen version of [`StructVectorMut`], which is
1414/// created via the [`freeze`](crate::VectorMutOps::freeze) method.
@@ -39,9 +39,7 @@ impl StructVector {
3939 /// - Any field vector has a length that does not match the length of other fields.
4040 /// - The validity mask length does not match the field length.
4141 pub fn new ( fields : Box < [ Vector ] > , validity : Mask ) -> Self {
42- Self :: try_new ( fields, validity) . vortex_expect (
43- "`StructVector` fields must have matching length and validity constraints" ,
44- )
42+ Self :: try_new ( fields, validity) . vortex_expect ( "Failed to create `StructVector`" )
4543 }
4644
4745 /// Tries to create a new [`StructVector`] from the given fields and validity mask.
@@ -59,7 +57,24 @@ impl StructVector {
5957 fields[ 0 ] . len ( )
6058 } ;
6159
62- Self :: validate ( & fields, len, & validity) ?;
60+ // Validate that the validity mask has the correct length.
61+ vortex_ensure ! (
62+ validity. len( ) == len,
63+ "Validity mask length ({}) does not match expected length ({})" ,
64+ validity. len( ) ,
65+ len
66+ ) ;
67+
68+ // Validate that all fields have the correct length.
69+ for ( i, field) in fields. iter ( ) . enumerate ( ) {
70+ vortex_ensure ! (
71+ field. len( ) == len,
72+ "Field {} has length {} but expected length {}" ,
73+ i,
74+ field. len( ) ,
75+ len
76+ ) ;
77+ }
6378
6479 Ok ( Self {
6580 fields,
@@ -83,47 +98,15 @@ impl StructVector {
8398 fields[ 0 ] . len ( )
8499 } ;
85100
86- debug_assert ! (
87- Self :: validate( & fields, len, & validity) . is_ok( ) ,
88- "`StructVector` fields must have matching length and validity constraints"
89- ) ;
90-
91- Self {
92- fields,
93- validity,
94- len,
95- }
96- }
97-
98- /// Validates the fields and validity mask for a [`StructVector`].
99- ///
100- /// # Errors
101- ///
102- /// Returns an error if:
103- ///
104- /// - Any field vector has a length that does not match the length of other fields.
105- /// - The validity mask length does not match the field length.
106- fn validate ( fields : & [ Vector ] , len : usize , validity : & Mask ) -> VortexResult < ( ) > {
107- // Validate that the validity mask has the correct length.
108- vortex_ensure ! (
109- validity. len( ) == len,
110- "Validity mask length ({}) does not match expected length ({})" ,
111- validity. len( ) ,
112- len
113- ) ;
114-
115- // Validate that all fields have the correct length.
116- for ( i, field) in fields. iter ( ) . enumerate ( ) {
117- vortex_ensure ! (
118- field. len( ) == len,
119- "Field {} has length {} but expected length {}" ,
120- i,
121- field. len( ) ,
122- len
123- ) ;
101+ if cfg ! ( debug_assertions) {
102+ Self :: new ( fields, validity)
103+ } else {
104+ Self {
105+ fields,
106+ validity,
107+ len,
108+ }
124109 }
125-
126- Ok ( ( ) )
127110 }
128111
129112 /// Decomposes the struct vector into its constituent parts (fields, validity, and length).
@@ -172,7 +155,6 @@ impl VectorOps for StructVector {
172155 Err ( immutable_field) => {
173156 // We were unable to take ownership, so we must re-freeze all of the fields
174157 // vectors we took ownership over and reconstruct the original `StructVector`.
175-
176158 let mut all_fields: Vec < Vector > = mutable_fields
177159 . into_iter ( )
178160 . map ( |mut_field| mut_field. freeze ( ) )
0 commit comments