@@ -139,17 +139,20 @@ impl<'a> DynToken<'a> {
139139
140140 /// Decodes from a decoder, populating the structure with the decoded data.
141141 #[ inline]
142- pub ( crate ) fn decode_populate ( & mut self , dec : & mut Decoder < ' a > ) -> Result < ( ) > {
142+ pub ( crate ) fn decode_populate ( & mut self , dec : & mut Decoder < ' a , ' _ > ) -> Result < ( ) > {
143143 match self {
144144 Self :: Word ( w) => * w = WordToken :: decode_from ( dec) ?. 0 ,
145145 Self :: FixedSeq ( ..) => {
146- let dynamic = self . is_dynamic ( ) ;
147- let mut child = if dynamic { dec. take_indirection ( ) } else { dec. raw_child ( ) } ?;
148-
149- self . decode_sequence_populate ( & mut child) ?;
150-
151- if !dynamic {
152- dec. take_offset_from ( & child) ;
146+ if self . is_dynamic ( ) {
147+ let mut child = dec. take_indirection ( ) ?;
148+ self . decode_sequence_populate ( & mut child) ?;
149+ } else {
150+ let offset = {
151+ let mut child = dec. raw_child ( ) ?;
152+ self . decode_sequence_populate ( & mut child) ?;
153+ dec. offset_from_child ( & child)
154+ } ;
155+ dec. set_offset ( offset) ;
153156 }
154157 }
155158 Self :: DynSeq { contents, template } => {
@@ -189,6 +192,7 @@ impl<'a> DynToken<'a> {
189192 // re-use the box allocation
190193 unsafe { Vec :: from_raw_parts ( Box :: into_raw ( template) , 1 , 1 ) }
191194 } else {
195+ child. reserve_elements :: < Self > ( size) ?;
192196 try_vec ! [ * template; size] ?
193197 } ;
194198
@@ -206,7 +210,7 @@ impl<'a> DynToken<'a> {
206210 /// Decode a sequence from the decoder, populating the data by consuming
207211 /// decoder words.
208212 #[ inline]
209- pub ( crate ) fn decode_sequence_populate ( & mut self , dec : & mut Decoder < ' a > ) -> Result < ( ) > {
213+ pub ( crate ) fn decode_sequence_populate ( & mut self , dec : & mut Decoder < ' a , ' _ > ) -> Result < ( ) > {
210214 match self {
211215 Self :: FixedSeq ( buf, size) => {
212216 buf. to_mut ( ) . iter_mut ( ) . take ( * size) . try_for_each ( |item| item. decode_populate ( dec) )
@@ -218,7 +222,7 @@ impl<'a> DynToken<'a> {
218222
219223 /// Decode a single item of this type, as a sequence of length 1.
220224 #[ inline]
221- pub ( crate ) fn decode_single_populate ( & mut self , dec : & mut Decoder < ' a > ) -> Result < ( ) > {
225+ pub ( crate ) fn decode_single_populate ( & mut self , dec : & mut Decoder < ' a , ' _ > ) -> Result < ( ) > {
222226 // This is what
223227 // `Self::FixedSeq(vec![self.clone()], 1).decode_populate()`
224228 // would do, so we skip the allocation.
0 commit comments