Skip to content

Commit 86a7f22

Browse files
committed
qt-build-utils: add back a cache for finding the Qt tool
1 parent e900451 commit 86a7f22

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

crates/qt-build-utils/src/installation/qmake.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
use semver::Version;
77
use std::{
8+
cell::RefCell,
9+
collections::HashMap,
810
env,
911
io::ErrorKind,
1012
path::{Path, PathBuf},
@@ -17,6 +19,8 @@ use crate::{parse_cflags, utils, QtBuildError, QtInstallation, QtTool};
1719
pub struct QtInstallationQMake {
1820
qmake_path: PathBuf,
1921
qmake_version: Version,
22+
// Internal cache of paths for tools
23+
tool_cache: RefCell<HashMap<QtTool, Option<PathBuf>>>,
2024
}
2125

2226
impl QtInstallationQMake {
@@ -128,6 +132,7 @@ impl TryFrom<PathBuf> for QtInstallationQMake {
128132
Ok(Self {
129133
qmake_path,
130134
qmake_version,
135+
tool_cache: HashMap::default().into(),
131136
})
132137
}
133138
}
@@ -246,7 +251,18 @@ impl QtInstallation for QtInstallationQMake {
246251
}
247252

248253
fn try_find_tool(&self, tool: QtTool) -> Option<PathBuf> {
249-
self.try_qmake_find_tool(tool.binary_name())
254+
let find_tool_closure = |tool: &QtTool| self.try_qmake_find_tool(tool.binary_name());
255+
256+
// Attempt to use the cache
257+
if let Ok(mut tool_cache) = self.tool_cache.try_borrow_mut() {
258+
// Read the tool from the cache or insert
259+
tool_cache
260+
.entry(tool)
261+
.or_insert_with_key(find_tool_closure)
262+
.to_owned()
263+
} else {
264+
find_tool_closure(&tool)
265+
}
250266
}
251267

252268
fn version(&self) -> semver::Version {

crates/qt-build-utils/src/tool.rs

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
/// An enum representing known Qt tools
77
#[non_exhaustive]
8+
#[derive(Eq, Hash, PartialEq)]
89
pub enum QtTool {
910
/// Moc
1011
Moc,

0 commit comments

Comments
 (0)