summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_serialize/src/leb128.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--compiler/rustc_serialize/src/leb128.rs21
1 files changed, 9 insertions, 12 deletions
diff --git a/compiler/rustc_serialize/src/leb128.rs b/compiler/rustc_serialize/src/leb128.rs
index 08b3c0542..7dad9aa01 100644
--- a/compiler/rustc_serialize/src/leb128.rs
+++ b/compiler/rustc_serialize/src/leb128.rs
@@ -1,22 +1,19 @@
-#![macro_use]
-
-macro_rules! max_leb128_len {
- ($int_ty:ty) => {
- // The longest LEB128 encoding for an integer uses 7 bits per byte.
- (std::mem::size_of::<$int_ty>() * 8 + 6) / 7
- };
+/// 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_leb128_len() -> usize {
- max_leb128_len!(u128)
+/// 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>()
}
macro_rules! impl_write_unsigned_leb128 {
($fn_name:ident, $int_ty:ty) => {
#[inline]
pub fn $fn_name(
- out: &mut [::std::mem::MaybeUninit<u8>; max_leb128_len!($int_ty)],
+ out: &mut [::std::mem::MaybeUninit<u8>; max_leb128_len::<$int_ty>()],
mut value: $int_ty,
) -> &[u8] {
let mut i = 0;
@@ -90,7 +87,7 @@ macro_rules! impl_write_signed_leb128 {
($fn_name:ident, $int_ty:ty) => {
#[inline]
pub fn $fn_name(
- out: &mut [::std::mem::MaybeUninit<u8>; max_leb128_len!($int_ty)],
+ out: &mut [::std::mem::MaybeUninit<u8>; max_leb128_len::<$int_ty>()],
mut value: $int_ty,
) -> &[u8] {
let mut i = 0;