lazy_static => once_cell

main
Tassilo Horn 2 years ago
parent b778869ca3
commit 59fa701ab5
  1. 2
      Cargo.lock
  2. 2
      Cargo.toml
  3. 19
      src/cmds.rs
  4. 13
      src/fmt_replace.rs
  5. 32
      src/tree.rs
  6. 23
      src/util.rs

2
Cargo.lock generated

@ -554,8 +554,8 @@ dependencies = [
"clap",
"directories",
"env_logger",
"lazy_static",
"log",
"once_cell",
"rand",
"regex",
"rt-format",

@ -17,7 +17,6 @@ swayipc = "3.0.0"
toml = "0.5.8"
directories = "4.0"
regex = "1.5.5"
lazy_static = "1.4.0"
rand = "0.8.4"
rt-format = "0.3.0"
log = "0.4"
@ -25,6 +24,7 @@ env_logger = { version = "0.9.0", default-features = false, features = ["termcol
swaybar-types = "3.0.0"
chrono = "0.4"
sysinfo = "0.23"
once_cell = "1.10.0"
[profile.release]
lto = "thin"

@ -21,8 +21,9 @@ use crate::tree as t;
use crate::tree::NodeMethods;
use crate::util;
use crate::util::DisplayFormat;
use lazy_static::lazy_static;
use once_cell::sync::Lazy;
use rand::prelude::SliceRandom;
use regex::Regex;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::sync::atomic;
@ -537,10 +538,8 @@ pub fn focus_win_if_not_focused(
}
}
lazy_static! {
static ref DIGIT_AND_NAME: regex::Regex =
regex::Regex::new(r"^(\d):(.*)").unwrap();
}
static DIGIT_AND_NAME: Lazy<Regex> =
Lazy::new(|| Regex::new(r"^(\d):(.*)").unwrap());
fn create_workspace(ws_name: &str) {
if DIGIT_AND_NAME.is_match(ws_name) {
@ -550,12 +549,10 @@ fn create_workspace(ws_name: &str) {
}
}
lazy_static! {
static ref SPECIAL_WORKSPACE: regex::Regex =
regex::Regex::new(r"^#*w:(.*)").unwrap();
static ref SPECIAL_SWAY: regex::Regex =
regex::Regex::new(r"^#*s:(.*)").unwrap();
}
static SPECIAL_WORKSPACE: Lazy<Regex> =
Lazy::new(|| Regex::new(r"^#*w:(.*)").unwrap());
static SPECIAL_SWAY: Lazy<regex::Regex> =
Lazy::new(|| Regex::new(r"^#*s:(.*)").unwrap());
fn chop_workspace_shortcut(input: &str) -> &str {
match SPECIAL_WORKSPACE.captures(input) {

@ -13,14 +13,15 @@
// You should have received a copy of the GNU General Public License along with
// this program. If not, see <https://www.gnu.org/licenses/>.
use lazy_static::lazy_static;
use once_cell::sync::Lazy;
use regex::Regex;
lazy_static! {
pub static ref PLACEHOLDER_RX: regex::Regex = regex::Regex::new(
r"\{(?P<name>[^}:]+)(?::(?P<fmtstr>\{[^}]*\})(?P<clipstr>[^}]*))?\}"
pub static PLACEHOLDER_RX: Lazy<Regex> = Lazy::new(|| {
Regex::new(
r"\{(?P<name>[^}:]+)(?::(?P<fmtstr>\{[^}]*\})(?P<clipstr>[^}]*))?\}",
)
.unwrap();
}
.unwrap()
});
pub fn maybe_html_escape(do_it: bool, text: String) -> String {
if do_it {

@ -18,25 +18,33 @@
use crate::config;
use crate::util;
use crate::util::DisplayFormat;
use lazy_static::lazy_static;
use once_cell::sync::Lazy;
use regex::Regex;
use serde::{Deserialize, Serialize};
use std::cell::RefCell;
use std::cmp;
use std::collections::HashMap;
use std::rc::Rc;
use std::sync::Mutex;
use swayipc as s;
static SWAY_IPC_CONNECTION: Lazy<Mutex<RefCell<s::Connection>>> =
Lazy::new(|| {
Mutex::new(RefCell::new(
s::Connection::new().expect("Could not open sway IPC connection."),
))
});
pub fn get_root_node(include_scratchpad: bool) -> s::Node {
match s::Connection::new() {
Ok(mut con) => {
let mut root = con.get_tree().expect("Got no root node");
if !include_scratchpad {
root.nodes.retain(|o| !o.is_scratchpad());
}
root
}
let mut root = match SWAY_IPC_CONNECTION.lock() {
Ok(cell) => cell.borrow_mut().get_tree().expect("Couldn't get tree"),
Err(err) => panic!("{}", err),
};
if !include_scratchpad {
root.nodes.retain(|o| !o.is_scratchpad());
}
root
}
/// Immutable Node Iterator
@ -441,10 +449,8 @@ pub fn get_tree<'a>(
}
}
lazy_static! {
static ref APP_NAME_AND_VERSION_RX: regex::Regex =
regex::Regex::new("(.+)(-[0-9.]+)").unwrap();
}
static APP_NAME_AND_VERSION_RX: Lazy<Regex> =
Lazy::new(|| Regex::new("(.+)(-[0-9.]+)").unwrap());
fn format_marks(marks: &[String]) -> String {
if marks.is_empty() {

@ -15,12 +15,15 @@
//! Utility functions including selection between choices using a menu program.
use once_cell::sync::Lazy;
use regex::Regex;
use crate::config as cfg;
use lazy_static::lazy_static;
use std::collections::HashMap;
use std::io::{BufRead, Write};
use std::path as p;
use std::process as proc;
use std::sync::Mutex;
pub fn get_swayr_socket_path() -> String {
// We prefer checking the env variable instead of
@ -120,12 +123,10 @@ fn find_icon(icon_name: &str, icon_dirs: &[String]) -> Option<Box<p::Path>> {
None
}
lazy_static! {
static ref WM_CLASS_OR_ICON_RX: regex::Regex =
regex::Regex::new(r"(StartupWMClass|Icon)=(.+)").unwrap();
static ref REV_DOMAIN_NAME_RX: regex::Regex =
regex::Regex::new(r"^(?:[a-zA-Z0-9-]+\.)+([a-zA-Z0-9-]+)$").unwrap();
}
static WM_CLASS_OR_ICON_RX: Lazy<Regex> =
Lazy::new(|| Regex::new(r"(StartupWMClass|Icon)=(.+)").unwrap());
static REV_DOMAIN_NAME_RX: Lazy<Regex> =
Lazy::new(|| Regex::new(r"^(?:[a-zA-Z0-9-]+\.)+([a-zA-Z0-9-]+)$").unwrap());
fn get_app_id_to_icon_map(
icon_dirs: &[String],
@ -195,10 +196,10 @@ fn get_app_id_to_icon_map(
map
}
lazy_static! {
static ref APP_ID_TO_ICON_MAP: std::sync::Mutex<Option<HashMap<String, Box<p::Path>>>> =
std::sync::Mutex::new(None);
}
// Well, this type definition is pretty useless since it's only used in
// get_icon anyway but clippy suggested it...
type AppIdToIconMap = Lazy<Mutex<Option<HashMap<String, Box<p::Path>>>>>;
static APP_ID_TO_ICON_MAP: AppIdToIconMap = Lazy::new(|| Mutex::new(None));
pub fn get_icon(app_id: &str, icon_dirs: &[String]) -> Option<Box<p::Path>> {
let mut opt = APP_ID_TO_ICON_MAP.lock().unwrap();

Loading…
Cancel
Save