rust-analyzer/crates/test-utils/src/bench_fixture.rs
Yuri Astrakhan d3dbf9c194 Moar linting: needless_borrow, let_unit_value, ...
* There are a few needless borrows that don't seem to be needed. I even did a quick assembly comparison and posted a q to stackoveflow on it. See [here](https://stackoverflow.com/questions/74910196/advantages-of-pass-by-ref-val-with-impl-intoiteratoritem-impl-asrefstr)
* removed several `let _ = ...` when they don't look necessary (even a few ones that were not suggested by clippy (?))
* there were a few `then(|| ctor{})` that clippy suggested to replace with `then_some(ctor{})` -- seems reasonable?
* some unneeded assignment+return - keep the code a bit leaner
* a few `writeln!` instead of `write!`, or even consolidate write!
* a nice optimization to use `ch.is_ascii_digit` instead of `ch.is_digit(10)`
2022-12-25 05:07:47 -05:00

45 lines
948 B
Rust

//! Generates large snippets of Rust code for usage in the benchmarks.
use std::fs;
use stdx::format_to;
use crate::project_root;
pub fn big_struct() -> String {
let n = 1_000;
big_struct_n(n)
}
pub fn big_struct_n(n: u32) -> String {
let mut buf = "pub struct RegisterBlock {".to_string();
for i in 0..n {
format_to!(buf, " /// Doc comment for {}.\n", i);
format_to!(buf, " pub s{}: S{},\n", i, i);
}
buf.push_str("}\n\n");
for i in 0..n {
format_to!(
buf,
"
#[repr(transparent)]
struct S{} {{
field: u32,
}}",
i
);
}
buf
}
pub fn glorious_old_parser() -> String {
let path = project_root().join("bench_data/glorious_old_parser");
fs::read_to_string(path).unwrap()
}
pub fn numerous_macro_rules() -> String {
let path = project_root().join("bench_data/numerous_macro_rules");
fs::read_to_string(path).unwrap()
}