swf: Optimize `count_ubits()`

Use `u32::leading_zeros()` instead of manually counting bits.
This commit is contained in:
relrelb 2022-10-08 19:57:05 +05:45 committed by relrelb
parent bf0ace0b88
commit 2b9f0a6280
1 changed files with 2 additions and 7 deletions

View File

@ -2369,13 +2369,8 @@ impl<W: Write> Writer<W> {
} }
} }
fn count_ubits(mut n: u32) -> u32 { fn count_ubits(n: u32) -> u32 {
let mut num_bits = 0; 32 - n.leading_zeros()
while n > 0 {
n >>= 1;
num_bits += 1;
}
num_bits
} }
fn count_sbits(n: i32) -> u32 { fn count_sbits(n: i32) -> u32 {