core: Replace consecutive `push`es with `extend`

This should be slightly more efficient.
This commit is contained in:
relrelb 2022-09-10 11:07:48 +03:00 committed by relrelb
parent e40229d90b
commit 9d4ab37ef6
3 changed files with 3 additions and 8 deletions

View File

@ -397,9 +397,7 @@ pub fn escape<'gc>(
// ECMA-262 violation: Avm1 does not support unicode escapes. // ECMA-262 violation: Avm1 does not support unicode escapes.
_ => { _ => {
const DIGITS: &[u8; 16] = b"0123456789ABCDEF"; const DIGITS: &[u8; 16] = b"0123456789ABCDEF";
buffer.push(b'%'); buffer.extend([b'%', DIGITS[(c / 16) as usize], DIGITS[(c % 16) as usize]]);
buffer.push(DIGITS[(c / 16) as usize]);
buffer.push(DIGITS[(c % 16) as usize]);
} }
}; };
} }

View File

@ -565,8 +565,7 @@ fn f64_to_string(mut n: f64) -> Cow<'static, str> {
// 1.2345e+15 // 1.2345e+15
// This case fails to push an extra 0 to handle the rounding 9.9999 -> 10, which // This case fails to push an extra 0 to handle the rounding 9.9999 -> 10, which
// causes the -9999999999999999.0 -> "-e+16" bug later. // causes the -9999999999999999.0 -> "-e+16" bug later.
buf.push(digit()); buf.extend([digit(), b'.']);
buf.push(b'.');
for _ in 0..MAX_DECIMAL_PLACES - 1 { for _ in 0..MAX_DECIMAL_PLACES - 1 {
buf.push(digit()); buf.push(digit());
} }

View File

@ -1269,9 +1269,7 @@ fn solve_cubic(a: f64, b: f64, c: f64, d: f64) -> SmallVec<[f64; 3]> {
let t0 = r * f64::cos(theta / 3.0) - offset; let t0 = r * f64::cos(theta / 3.0) - offset;
let t1 = r * f64::cos((theta + 2.0 * std::f64::consts::PI) / 3.0) - offset; let t1 = r * f64::cos((theta + 2.0 * std::f64::consts::PI) / 3.0) - offset;
let t2 = r * f64::cos((theta + 4.0 * std::f64::consts::PI) / 3.0) - offset; let t2 = r * f64::cos((theta + 4.0 * std::f64::consts::PI) / 3.0) - offset;
roots.push(t0); roots.extend([t0, t1, t2]);
roots.push(t1);
roots.push(t2);
} else { } else {
let gamma1 = f64::cbrt(q + f64::sqrt(-disc)); let gamma1 = f64::cbrt(q + f64::sqrt(-disc));
let gamma2 = f64::cbrt(q - f64::sqrt(-disc)); let gamma2 = f64::cbrt(q - f64::sqrt(-disc));