summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_data_structures/src/base_n.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:59:35 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:59:35 +0000
commitd1b2d29528b7794b41e66fc2136e395a02f8529b (patch)
treea4a17504b260206dec3cf55b2dca82929a348ac2 /compiler/rustc_data_structures/src/base_n.rs
parentReleasing progress-linux version 1.72.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-d1b2d29528b7794b41e66fc2136e395a02f8529b.tar.xz
rustc-d1b2d29528b7794b41e66fc2136e395a02f8529b.zip
Merging upstream version 1.73.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_data_structures/src/base_n.rs')
-rw-r--r--compiler/rustc_data_structures/src/base_n.rs10
1 files changed, 6 insertions, 4 deletions
diff --git a/compiler/rustc_data_structures/src/base_n.rs b/compiler/rustc_data_structures/src/base_n.rs
index 4567759c0..a3eb2b9c4 100644
--- a/compiler/rustc_data_structures/src/base_n.rs
+++ b/compiler/rustc_data_structures/src/base_n.rs
@@ -16,22 +16,24 @@ const BASE_64: &[u8; MAX_BASE] =
pub fn push_str(mut n: u128, base: usize, output: &mut String) {
debug_assert!(base >= 2 && base <= MAX_BASE);
let mut s = [0u8; 128];
- let mut index = 0;
+ let mut index = s.len();
let base = base as u128;
loop {
+ index -= 1;
s[index] = BASE_64[(n % base) as usize];
- index += 1;
n /= base;
if n == 0 {
break;
}
}
- s[0..index].reverse();
- output.push_str(str::from_utf8(&s[0..index]).unwrap());
+ output.push_str(unsafe {
+ // SAFETY: `s` is populated using only valid utf8 characters from `BASE_64`
+ str::from_utf8_unchecked(&s[index..])
+ });
}
#[inline]