mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 16:24:46 +00:00
rename {max=>largest}_max_leb128_len
This commit is contained in:
parent
050cee48f8
commit
8c0951511b
@ -1,11 +1,11 @@
|
||||
/// Returns the longest LEB128 encoding for `T`, assuming `T` is an integer type
|
||||
/// Returns the length of the longest LEB128 encoding for `T`, assuming `T` is an integer type
|
||||
pub const fn max_leb128_len<T>() -> usize {
|
||||
// The longest LEB128 encoding for an integer uses 7 bits per byte.
|
||||
(std::mem::size_of::<T>() * 8 + 6) / 7
|
||||
}
|
||||
|
||||
/// Returns the longest LEB128 encoding of all supported integer types.
|
||||
pub const fn max_max_leb128_len() -> usize {
|
||||
/// Returns the length of the longest LEB128 encoding of all supported integer types.
|
||||
pub const fn largest_max_leb128_len() -> usize {
|
||||
max_leb128_len::<u128>()
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::leb128::{self, max_max_leb128_len};
|
||||
use crate::leb128::{self, largest_max_leb128_len};
|
||||
use crate::serialize::{Decodable, Decoder, Encodable, Encoder};
|
||||
use std::convert::TryInto;
|
||||
use std::fs::File;
|
||||
@ -186,12 +186,12 @@ impl FileEncoder {
|
||||
pub fn with_capacity<P: AsRef<Path>>(path: P, capacity: usize) -> io::Result<Self> {
|
||||
// Require capacity at least as large as the largest LEB128 encoding
|
||||
// here, so that we don't have to check or handle this on every write.
|
||||
assert!(capacity >= max_max_leb128_len());
|
||||
assert!(capacity >= largest_max_leb128_len());
|
||||
|
||||
// Require capacity small enough such that some capacity checks can be
|
||||
// done using guaranteed non-overflowing add rather than sub, which
|
||||
// shaves an instruction off those code paths (on x86 at least).
|
||||
assert!(capacity <= usize::MAX - max_max_leb128_len());
|
||||
assert!(capacity <= usize::MAX - largest_max_leb128_len());
|
||||
|
||||
// Create the file for reading and writing, because some encoders do both
|
||||
// (e.g. the metadata encoder when -Zmeta-stats is enabled)
|
||||
|
Loading…
Reference in New Issue
Block a user