diff options
| author | Matthias Krüger <476013+matthiaskrgr@users.noreply.github.com> | 2025-07-06 10:03:23 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-06 10:03:23 +0200 |
| commit | 6fb00b1514174f215b09afbc574f15f196eb556a (patch) | |
| tree | 9b70264127b960e591d48e6fbca1fcaf13ffcaf6 /compiler/rustc_index | |
| parent | 19f8ba4733c3eb8fa98ba06be63df8b621625d0b (diff) | |
| parent | ed3711ea29398b09483e4e2a3930567e9ba81d93 (diff) | |
| download | rust-6fb00b1514174f215b09afbc574f15f196eb556a.tar.gz rust-6fb00b1514174f215b09afbc574f15f196eb556a.zip | |
Rollup merge of #143477 - folkertdev:use-is-multiple-of, r=joshtriplett
use `is_multiple_of` and `div_ceil` In tricky logic, these functions are much more informative than the manual implementations. They also catch subtle bugs: - the manual `is_multiple_of` often does not handle division by zero - manual `div_ceil` often does not consider overflow The transformation is free for `is_multiple_of` if the divisor is compile-time known to be non-zero. For `div_ceil` there is a small cost to considering overflow. Here is some assembly https://godbolt.org/z/5zP8KaE1d.
Diffstat (limited to 'compiler/rustc_index')
| -rw-r--r-- | compiler/rustc_index/src/bit_set.rs | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/compiler/rustc_index/src/bit_set.rs b/compiler/rustc_index/src/bit_set.rs index a4885aabe1f..645d95b1dba 100644 --- a/compiler/rustc_index/src/bit_set.rs +++ b/compiler/rustc_index/src/bit_set.rs @@ -1744,13 +1744,13 @@ impl<R: Idx, C: Idx> SparseBitMatrix<R, C> { #[inline] fn num_words<T: Idx>(domain_size: T) -> usize { - (domain_size.index() + WORD_BITS - 1) / WORD_BITS + domain_size.index().div_ceil(WORD_BITS) } #[inline] fn num_chunks<T: Idx>(domain_size: T) -> usize { assert!(domain_size.index() > 0); - (domain_size.index() + CHUNK_BITS - 1) / CHUNK_BITS + domain_size.index().div_ceil(CHUNK_BITS) } #[inline] |
