diff --git a/.circleci/config.yml b/.circleci/config.yml index bd19cd6..1a0c76f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -14,7 +14,7 @@ workflows: # be easier on the CI hosts since presumably those fat lower layers will already be cached, and # therefore faster than a minimal, customized alpine. # MSRV - 'rust:1.47.0' + 'rust:1.51.0' ] # a hacky scheme to work around CircleCI's inability to deal with mutable docker tags, forcing us to # get a nightly or stable toolchain via rustup instead of a mutable docker tag diff --git a/Cargo.toml b/Cargo.toml index bd601ea..9592b7c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ keywords = ["base64", "utf8", "encode", "decode", "no_std"] categories = ["encoding"] license = "MIT OR Apache-2.0" edition = "2018" -rust-version = "1.47.0" +rust-version = "1.51.0" [[bench]] name = "benchmarks" diff --git a/README.md b/README.md index 2b87943..f48a201 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ If you have a `Read` (e.g. reading a file or network socket), there are various ## Rust version compatibility -The minimum required Rust version is 1.47.0. +The minimum required Rust version is 1.51.0. # Contributing diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 7b11df9..eaf84dc 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -1,5 +1,9 @@ # 0.20.0 +## Next + +- MSRV is now 1.51.0 to keep up with `criterion` + ## 0.20.0-alpha.1 ### Breaking changes @@ -13,6 +17,10 @@ - `DecoderReader` now owns its inner reader, and can expose it via `into_inner()`. For symmetry, `EncoderWriter` can do the same with its writer. - `encoded_len` is now public so you can size encode buffers precisely. +# 0.13.1 + +- More precise decode buffer sizing, avoiding unnecessary allocation in `decode_config`. + # 0.13.0 - Config methods are const diff --git a/clippy.toml b/clippy.toml index dbabdab..434e968 100644 --- a/clippy.toml +++ b/clippy.toml @@ -1 +1 @@ -msrv = "1.47.0" +msrv = "1.51.0" diff --git a/src/decode.rs b/src/decode.rs index d7b4195..04db879 100644 --- a/src/decode.rs +++ b/src/decode.rs @@ -95,7 +95,14 @@ pub fn decode_engine>( input: T, engine: &E, ) -> Result, DecodeError> { - let mut buffer = Vec::::new(); + let decoded_length_estimate = (input + .as_ref() + .len() + .checked_add(3) + .expect("decoded length calculation overflow")) + / 4 + * 3; + let mut buffer = Vec::::with_capacity(decoded_length_estimate); decode_engine_vec(input, &mut buffer, engine).map(|_| buffer) } @@ -340,4 +347,17 @@ mod tests { assert_eq!(orig_data, decode_buf); } } + + #[test] + fn decode_engine_estimation_works_for_various_lengths() { + for num_prefix_quads in 0..100 { + for suffix in &["AA", "AAA", "AAAA"] { + let mut prefix = "AAAA".repeat(num_prefix_quads); + prefix.push_str(suffix); + // make sure no overflow (and thus a panic) occurs + let res = decode_engine(prefix, &DEFAULT_ENGINE); + assert!(res.is_ok()); + } + } + } }