reduce predicate overhead

This commit is contained in:
Rasmus Moorats 2024-08-30 14:31:35 +03:00
parent 9eb250b813
commit d25ddb487e
Signed by: xx
GPG key ID: FE14255A6AE7241C

View file

@ -61,20 +61,18 @@ fn main() -> Result<(), Box<dyn std::error::Error>>{
let cli = Cli::parse();
let mut connection = Connection::new()?;
let predicate: Box<dyn Fn(&Node) -> bool> = match cli.use_field {
UseField::Class => Box::new(|node: &Node| {
let node = match cli.use_field {
UseField::Class => find_node(&connection.get_tree()?, |node: &Node| {
node.window_properties
.as_ref()
.and_then(|p| p.class.as_deref())
== Some(&cli.identifier)
}),
UseField::AppId => Box::new(|node: &Node| {
UseField::AppId => find_node(&connection.get_tree()?, |node: &Node| {
node.app_id.as_deref() == Some(&cli.identifier)
}),
};
let node = find_node(&connection.get_tree()?, predicate.as_ref());
let sway_cmd = if let Some(node) = node {
if node.focused {
format!("[{}={}] move scratchpad", cli.use_field, cli.identifier)