havok_serde/de/size_hint.rs
1// SPDX-License-Identifier: Apache-2.0 OR MIT
2//
3// The following code was written by modifying serde ver. 1.0.202.
4// See: https://github.com/serde-rs/serde/commit/58b3af4c2915c3ae789778a11f3b7a468c1cec17
5//
6// And serde holds the same license as Rust. https://github.com/rust-lang/rust/pull/43498
7use crate::lib::*;
8
9#[cfg(any(feature = "std", feature = "alloc"))]
10pub fn cautious<Element>(hint: Option<usize>) -> usize {
11 const MAX_PREALLOC_BYTES: usize = 1024 * 1024;
12
13 if mem::size_of::<Element>() == 0 {
14 0
15 } else {
16 cmp::min(
17 hint.unwrap_or(0),
18 MAX_PREALLOC_BYTES / mem::size_of::<Element>(),
19 )
20 }
21}