mirror of
https://github.com/swc-project/swc.git
synced 2024-11-27 04:47:03 +03:00
perf(es/minifier): Use Vec<u8>
as a buffer for base54
(#3993)
Description: We are only using ASCII characters so we can avoid utf8 logics by using `Vec<u8>` as a buffer and converting it into `String` at the end.
This commit is contained in:
parent
63177b7cf2
commit
f7b212bfc4
@ -24,21 +24,24 @@ pub(crate) fn encode(init: &mut usize, skip_reserved: bool) -> String {
|
||||
base <<= 6;
|
||||
}
|
||||
|
||||
let mut ret = String::new();
|
||||
let mut ret = vec![];
|
||||
|
||||
base /= 54;
|
||||
let mut c = BASE54_DEFAULT_CHARS[n / base] as char;
|
||||
let mut c = BASE54_DEFAULT_CHARS[n / base];
|
||||
ret.push(c);
|
||||
|
||||
while base > 1 {
|
||||
n %= base;
|
||||
base >>= 6;
|
||||
c = BASE54_DEFAULT_CHARS[n / base] as char;
|
||||
c = BASE54_DEFAULT_CHARS[n / base];
|
||||
|
||||
ret.push(c);
|
||||
}
|
||||
|
||||
ret
|
||||
unsafe {
|
||||
// Safety: We are only using ascii characters
|
||||
String::from_utf8_unchecked(ret)
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
|
Loading…
Reference in New Issue
Block a user