Skip to content

Commit 4308b27

Browse files
Nemo157Joshua Nelson
authored andcommitted
Intern known targets
1 parent 750061b commit 4308b27

File tree

5 files changed

+33
-2
lines changed

5 files changed

+33
-2
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ strum = { version = "0.18.0", features = ["derive"] }
5252
lol_html = "0.2"
5353
font-awesome-as-a-crate = { path = "crates/font-awesome-as-a-crate" }
5454
dashmap = "3.11.10"
55+
string_cache = "0.8.0"
5556

5657
# Async
5758
tokio = { version = "0.2.22", features = ["rt-threaded"] }
@@ -98,6 +99,7 @@ rand = "0.7.3"
9899
time = "0.1"
99100
git2 = { version = "0.13", default-features = false }
100101
sass-rs = "0.2.2"
102+
string_cache_codegen = "0.5.1"
101103

102104
[[bench]]
103105
name = "html_parsing"

build.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ fn main() {
1919
if let Err(sass_err) = compile_sass() {
2020
panic!("Error compiling sass: {}", sass_err);
2121
}
22+
write_known_targets().unwrap();
2223
}
2324

2425
fn write_git_version() {
@@ -87,3 +88,21 @@ fn compile_sass() -> Result<(), Box<dyn Error>> {
8788

8889
Ok(())
8990
}
91+
92+
fn write_known_targets() -> std::io::Result<()> {
93+
use std::io::BufRead;
94+
95+
let targets: Vec<String> = std::process::Command::new("rustc")
96+
.args(&["--print", "target-list"])
97+
.output()?
98+
.stdout
99+
.lines()
100+
.filter(|s| s.as_ref().map_or(true, |s| !s.is_empty()))
101+
.collect::<std::io::Result<_>>()?;
102+
103+
string_cache_codegen::AtomType::new("target::TargetAtom", "target_atom!")
104+
.atoms(&targets)
105+
.write_to_file(&Path::new(&env::var("OUT_DIR").unwrap()).join("target_atom.rs"))?;
106+
107+
Ok(())
108+
}

src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ mod test;
2626
pub mod utils;
2727
mod web;
2828

29+
#[allow(dead_code)]
30+
mod target {
31+
//! [`crate::target::TargetAtom`] is an interned string type for rustc targets, such as
32+
//! `x86_64-unknown-linux-gnu`. See the [`string_cache`] docs for usage examples.
33+
include!(concat!(env!("OUT_DIR"), "/target_atom.rs"));
34+
}
35+
2936
use web::page::GlobalAlert;
3037

3138
// Warning message shown in the navigation bar of every page. Set to `None` to hide it.

src/metrics/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ mod macros;
33

44
use self::macros::MetricFromOpts;
55
use crate::db::Pool;
6+
use crate::target::TargetAtom;
67
use crate::BuildQueue;
78
use dashmap::DashMap;
89
use failure::Error;
@@ -81,7 +82,7 @@ metrics! {
8182
pub(crate) struct RecentlyAccessedReleases {
8283
krates: DashMap<i32, Instant>,
8384
versions: DashMap<i32, Instant>,
84-
platforms: DashMap<(i32, String), Instant>,
85+
platforms: DashMap<(i32, TargetAtom), Instant>,
8586
}
8687

8788
impl RecentlyAccessedReleases {
@@ -93,7 +94,7 @@ impl RecentlyAccessedReleases {
9394
self.krates.insert(krate, Instant::now());
9495
self.versions.insert(version, Instant::now());
9596
self.platforms
96-
.insert((version, target.to_owned()), Instant::now());
97+
.insert((version, TargetAtom::from(target)), Instant::now());
9798
}
9899

99100
pub(crate) fn gather(&self, metrics: &Metrics) {

0 commit comments

Comments
 (0)