(self, len: usize)
| 368 | |
| 369 | #[inline(always)] |
| 370 | fn serialize_tuple(self, len: usize) -> Result<Self::SerializeTuple> { |
| 371 | // Fast path: avoid overhead of tuple for 1 element. |
| 372 | if len == 1 { |
| 373 | return Ok(TupleSerializer { |
| 374 | encoders: std::slice::from_mut(self.lazy), |
| 375 | index_alloc: self.index_alloc, |
| 376 | }); |
| 377 | } |
| 378 | |
| 379 | // Copy of specify! macro that takes an additional len parameter to cold. |
| 380 | let lazy = &mut *self.lazy; |
| 381 | match lazy { |
| 382 | LazyEncoder::Specified { |
| 383 | specified: SpecifiedEncoder::Tuple(_), |
| 384 | .. |
| 385 | } => (), |
| 386 | _ => { |
| 387 | #[cold] |
| 388 | fn cold(me: &mut LazyEncoder, len: usize) { |
| 389 | let &mut LazyEncoder::Unspecified { reserved } = me else { |
| 390 | type_changed!(); |
| 391 | }; |
| 392 | *me = LazyEncoder::Specified { |
| 393 | specified: SpecifiedEncoder::Tuple(default_box_slice(len)), |
| 394 | index: usize::MAX, // We never use index for SpecifiedEncoder::Tuple. |
| 395 | }; |
| 396 | let LazyEncoder::Specified { specified, .. } = me else { |
| 397 | unreachable!(); |
| 398 | }; |
| 399 | if let Some(reserved) = reserved { |
| 400 | specified.reserve(reserved); |
| 401 | } |
| 402 | } |
| 403 | cold(lazy, len); |
| 404 | } |
| 405 | }; |
| 406 | let LazyEncoder::Specified { |
| 407 | specified: SpecifiedEncoder::Tuple(encoders), |
| 408 | .. |
| 409 | } = lazy else { |
| 410 | // Safety: see specify! macro which this is based on. |
| 411 | unsafe { std::hint::unreachable_unchecked() }; |
| 412 | }; |
| 413 | if encoders.len() != len { |
| 414 | type_changed!(); // Removes multiple bounds checks. |
| 415 | } |
| 416 | Ok(TupleSerializer { |
| 417 | encoders, |
| 418 | index_alloc: self.index_alloc, |
| 419 | }) |
| 420 | } |
| 421 | |
| 422 | #[inline(always)] |
| 423 | fn serialize_tuple_struct( |
no test coverage detected