diff options
author | Chirantan Ekbote <chirantan@chromium.org> | 2018-03-12 15:40:48 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-03-20 00:00:28 -0700 |
commit | fec86cc3aeb09ffb9b9c1f4165a822378ce64200 (patch) | |
tree | 514a88605598938920f06965d6bdd23bdcb50927 /sys_util/poll_token_derive/poll_token_derive.rs | |
parent | ed517d1bfe028564076ee45bd9412882c85ebbe7 (diff) | |
download | crosvm-fec86cc3aeb09ffb9b9c1f4165a822378ce64200.tar crosvm-fec86cc3aeb09ffb9b9c1f4165a822378ce64200.tar.gz crosvm-fec86cc3aeb09ffb9b9c1f4165a822378ce64200.tar.bz2 crosvm-fec86cc3aeb09ffb9b9c1f4165a822378ce64200.tar.lz crosvm-fec86cc3aeb09ffb9b9c1f4165a822378ce64200.tar.xz crosvm-fec86cc3aeb09ffb9b9c1f4165a822378ce64200.tar.zst crosvm-fec86cc3aeb09ffb9b9c1f4165a822378ce64200.zip |
poll_token_derive: Calculate variant bits without sizeof_val
Calculate the number of bits necessary to represent the enum variant using the next_power_of_two() and trailing_zeros() functions from the primitive usize type. Also add a test to ensure that the returned value is correct when there is only one variant in the enum. BUG=none TEST=unit tests Change-Id: Ibd15efd4f06e17a74489fee04ff19aca0dde68b2 Signed-off-by: Chirantan Ekbote <chirantan@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/959624 Reviewed-by: Zach Reizner <zachr@chromium.org>
Diffstat (limited to 'sys_util/poll_token_derive/poll_token_derive.rs')
-rw-r--r-- | sys_util/poll_token_derive/poll_token_derive.rs | 3 |
1 files changed, 1 insertions, 2 deletions
diff --git a/sys_util/poll_token_derive/poll_token_derive.rs b/sys_util/poll_token_derive/poll_token_derive.rs index 7af2de5..3506b4d 100644 --- a/sys_util/poll_token_derive/poll_token_derive.rs +++ b/sys_util/poll_token_derive/poll_token_derive.rs @@ -326,8 +326,7 @@ impl EnumModel { if self.variants.is_empty() { return 0; } - let variant_count = self.variants.len(); - (mem::size_of_val(&variant_count) as u32 * 8) - (variant_count - 1).leading_zeros() + self.variants.len().next_power_of_two().trailing_zeros() } // Generates the function body for `as_raw_token`. |