Skip to content

Commit

Permalink
Merge pull request #61 from cuviper/saturating-next_base
Browse files Browse the repository at this point in the history
sieve: Use `saturating_add` when computing `next_base`
  • Loading branch information
cuviper authored Jun 7, 2024
2 parents a859535 + 3c583c7 commit 0cdec74
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 37 deletions.
23 changes: 19 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ name: Continuous integration
on:
push:
branches:
- staging
- trying
- master
pull_request:

env:
CARGO_TERM_COLOR: always
Expand All @@ -21,10 +21,10 @@ jobs:
- rust: nightly
- rust: nightly-i686-unknown-linux-gnu
- rust: stable
target: mips64-unknown-linux-gnuabi64
target: s390x-unknown-linux-gnu

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
Expand All @@ -35,3 +35,18 @@ jobs:
env:
TARGET: ${{ matrix.target }}
run: ./ci/script.sh

# One job that "summarizes" the success state of this pipeline. This can then be added to branch
# protection, rather than having to add each job separately.
success:
name: bors
runs-on: ubuntu-latest
needs: [tests]
# Github branch protection is exceedingly silly and treats "jobs skipped because a dependency
# failed" as success. So we have to do some contortions to ensure the job fails if any of its
# dependencies fails.
if: always() # make sure this is never "skipped"
steps:
# Manually check the status of all dependencies. `if: failure()` does not work.
- name: check if any dependency failed
run: jq --exit-status 'all(.result == "success")' <<< '${{ toJson(needs) }}'
23 changes: 0 additions & 23 deletions .github/workflows/pr.yml

This file was deleted.

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,8 @@ tag-name = "{{crate_name}}-{{version}}"
[package.metadata.release]
sign-tag = true
tag-name = "{{crate_name}}-{{version}}"

# Make sure all our slow_tests still check overflows in --release tests.
# (This doesn't affect downstream dependents building these libraries.)
[profile.release]
overflow-checks = true
8 changes: 0 additions & 8 deletions bors.toml

This file was deleted.

6 changes: 4 additions & 2 deletions primal-sieve/src/sieve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ impl Sieve {
let bits = &self.seen[base].bits;

let current_base = base_byte_count * wheel::BYTE_MODULO;
let next_base = current_base + bits.len() * wheel::BYTE_MODULO / 8;
let next_base = current_base.saturating_add(bits.len() * wheel::BYTE_MODULO / 8);

SievePrimes {
early,
Expand Down Expand Up @@ -404,7 +404,9 @@ impl<'a> SievePrimes<'a> {
match self.bits.next() {
Some(Item { bits, .. }) => {
self.base = self.next_base;
self.next_base += bits.len() * wheel::BYTE_MODULO / 8;
self.next_base = self
.next_base
.saturating_add(bits.len() * wheel::BYTE_MODULO / 8);
self.ones = bits.ones_from(0);
true
},
Expand Down

0 comments on commit 0cdec74

Please sign in to comment.