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:
Donny/강동윤 2022-03-13 11:57:47 +09:00 committed by GitHub
parent 63177b7cf2
commit f7b212bfc4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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)]