This repository was archived by the owner on May 28, 2025. It is now read-only.
Commit 35dbef2
committed
Auto merge of rust-lang#82562 - llogiq:one-up-82248, r=oli-obk
Optimize counting digits in line numbers during error reporting further
This one-ups rust-lang#82248 by switching the strategy: Instead of dividing the value by 10 repeatedly, we compare with a limit that we multiply by 10 repeatedly. In my benchmarks, this took between 50% and 25% of the original time. The reasons for being faster are:
1. While LLVM is able to replace a division by constant with a multiply + shift, a plain multiplication is still faster. However, this doesn't even factor, because
2. Multiplication, unlike division, is const. We also use a simple for-loop instead of a more complex loop + break, which allows
3. rustc to const-fold the whole loop, and indeed the assembly output simply shows a series of comparisons.1 file changed
+26
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1713 | 1713 | | |
1714 | 1714 | | |
1715 | 1715 | | |
1716 | | - | |
1717 | | - | |
1718 | | - | |
1719 | | - | |
1720 | | - | |
1721 | | - | |
1722 | | - | |
1723 | | - | |
1724 | | - | |
1725 | | - | |
1726 | | - | |
1727 | | - | |
| 1716 | + | |
| 1717 | + | |
1728 | 1718 | | |
1729 | 1719 | | |
1730 | 1720 | | |
| |||
1952 | 1942 | | |
1953 | 1943 | | |
1954 | 1944 | | |
| 1945 | + | |
| 1946 | + | |
| 1947 | + | |
| 1948 | + | |
| 1949 | + | |
| 1950 | + | |
| 1951 | + | |
| 1952 | + | |
| 1953 | + | |
| 1954 | + | |
| 1955 | + | |
| 1956 | + | |
| 1957 | + | |
| 1958 | + | |
| 1959 | + | |
| 1960 | + | |
| 1961 | + | |
| 1962 | + | |
| 1963 | + | |
| 1964 | + | |
| 1965 | + | |
| 1966 | + | |
| 1967 | + | |
| 1968 | + | |
1955 | 1969 | | |
1956 | 1970 | | |
1957 | 1971 | | |
| |||
0 commit comments