alloy-rs / alloy-rs/ruint

`algorithms/div/knuth`: Can we re-use `r` here somehow? The problem is we

オープン
#631 コメント 0 件 リアクション 0 件 担当者 1 名 @decofe が担当を希望しています GitHub で見る
optimize tracker
主要言語
Rust
スター
225
フォーク
70
平均マージ
16時間 54分
マージ済み PR(30日)
8

説明

*On 2026-08-31 @decofe wrote in [`a9450b4`](https://github.com/alloy-rs/ruint/commit/a9450b499c03f259238c2955b9512de873a77e12) “chore: apply latest nightly rustfmt (#627)”:*

Can we re-use `r` here somehow? The problem is we
can not just shift the `r` or
borrow` because we need to accurately reproduce
the remainder and carry in the middle of a limb.
SAFETY: both slices have length `n`.

```rust
let (r, borrow) = r.overflowing_sub(u128::from(borrow));
numerator[j + n - 2] = DW::low(r);
numerator[j + n - 1] = DW::high(r);
borrow
} else {
// OPT: Can we re-use `r` here somehow? The problem is we
// can not just shift the `r` or
// `borrow` because we need to accurately reproduce
// the remainder and carry in the middle of a limb.
// SAFETY: both slices have length `n`.
let borrow = unsafe { submul_nx1(&mut numerator[j..j + n], divisor, q) };
let n2 = numerator.get(j + n).copied().unwrap_or_default();
borrow != n2
};

```
*From [`src/algorithms/div/knuth.rs:178`](https://github.com/alloy-rs/ruint/blob/a9450b499c03f259238c2955b9512de873a77e12/src/algorithms/div/knuth.rs#L178)*

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

調査の方向性

Start in src/algorithms/div/knuth.rs around line 178 and read the surrounding Knuth division logic, including submul_nx1 and the handling of r, borrow, and n2. Determine whether r can be reused in the else branch without changing the accurately reproduced remainder or carry; done means the optimization is justified and preserves the existing division behavior.

索引モデルが issue の本文から書いたものです。

評価

技術スタック
rust
領域
backend
issue の種類
リファクタリング
難易度
4/5
見積もり時間
3〜5日
活発さ
活発
明瞭さ
明確に書かれている
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。