about summary refs log tree commit diff
path: root/compiler/rustc_mir/src/transform/coverage/graph.rs
diff options
context:
space:
mode:
authorDylan DPC <dylan.dpc@gmail.com>2021-02-18 16:57:42 +0100
committerGitHub <noreply@github.com>2021-02-18 16:57:42 +0100
commit555db2da70fb10103263148d678a72901a455d50 (patch)
tree30e5343315e620910a5318cff531e095348a5d2b /compiler/rustc_mir/src/transform/coverage/graph.rs
parent5ca94cd00a0d571b6aeb092a7da4798124acfde2 (diff)
parent8a5c5681da3695e1c2e3f23bee43a7ebfdce6161 (diff)
downloadrust-555db2da70fb10103263148d678a72901a455d50.tar.gz
rust-555db2da70fb10103263148d678a72901a455d50.zip
Rollup merge of #82248 - nhwn:optimize-counting-digits, r=varkor
Optimize counting digits in line numbers during error reporting

Replaces `.to_string().len()` with simple loop and integer division, which avoids an unnecessary allocation.

Although I couldn't figure out how to directly profile `rustc`'s error reporting, I ran a microbenchmark on my machine (2.9 GHz Dual-Core Intel Core i5) on the two strategies for `0..100_000`, and the results seem promising:
```
test to_string_len ... bench:  12,124,792 ns/iter (+/- 700,652)
test while_loop    ... bench:      30,333 ns/iter (+/- 562)
```
The x86_64 disassembly reduces integer division to a multiplication + shift, so I don't think there's any problems with using integer division.

For more (micro)optimization, it would be nice if we could avoid the initial check to see if the line number is nonzero, but I don't think `self.get_max_line_num(span, children)` _guarantees_ a nonzero line number.
Diffstat (limited to 'compiler/rustc_mir/src/transform/coverage/graph.rs')
0 files changed, 0 insertions, 0 deletions