Skip to content

Commit

Permalink
Replace lazy_static with std LazyLock
Browse files Browse the repository at this point in the history
  • Loading branch information
declantsien committed Apr 14, 2024
1 parent df8b8fc commit cbf2d8f
Show file tree
Hide file tree
Showing 32 changed files with 131 additions and 161 deletions.
15 changes: 0 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ gleam = "0.15"
winit = { version = "0.29", default-features = false, features = ["rwh_06"]}
arboard = "3.3"
euclid = "0.22"
lazy_static = "1.4"
tokio = "1"
regex = "1.10"
syn = "2"
Expand Down
1 change: 0 additions & 1 deletion crates/codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ version = "0.1.0"
edition = "2021"

[dependencies]
lazy_static = "1.4"
libc = "0.2"
regex = "1.10"
cargo_metadata = { version = "0.18", optional = false }
Expand Down
10 changes: 5 additions & 5 deletions crates/codegen/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#[macro_use]
extern crate lazy_static;
#![feature(lazy_cell)]

mod data;
mod error;
use data::package_targets;
Expand All @@ -11,6 +11,7 @@ pub use data::with_root_crate;
use data::with_root_crate_checked;
pub use data::Package;
pub use error::BuildError;
use std::sync::LazyLock;

use std::env;
use std::ffi::OsStr;
Expand Down Expand Up @@ -248,9 +249,8 @@ impl<'a> ModuleParser<'a> {
}

fn parse_gc_protected_static(&mut self, line: &str) -> Result<String, LintMsg> {
lazy_static! {
static ref RE: Regex = Regex::new(r#"GC_protected_static!\((.+), .+\);"#).unwrap();
}
static RE: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r#"GC_protected_static!\((.+), .+\);"#).unwrap());

match RE.captures(line) {
Some(caps) => {
Expand Down
1 change: 0 additions & 1 deletion crates/colors/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ edition = "2021"
path = "lib.rs"

[dependencies]
lazy_static = "1.4.0"
8 changes: 4 additions & 4 deletions crates/colors/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use lazy_static::lazy_static;
#![feature(lazy_cell)]
use std::collections::HashMap;
use std::sync::LazyLock;

include!(concat!(env!("OUT_DIR"), "/colors.rs"));

lazy_static! {
pub static ref COLOR_MAP: HashMap<&'static str, (u8, u8, u8)> = init_color();
}
pub static COLOR_MAP: LazyLock<HashMap<&'static str, (u8, u8, u8)>> =
LazyLock::new(|| init_color());
1 change: 0 additions & 1 deletion crates/emacs-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ path = "src/lib.rs"

[dependencies]
libc = "0.2.153"
lazy_static = "1.4.0"
log = "0.4"
memoffset = "0.9"
raw-window-handle = { workspace = true, optional = true }
Expand Down
1 change: 1 addition & 0 deletions crates/emacs-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#![feature(never_type)]
#![feature(stmt_expr_attributes)]
#![feature(async_closure)]
#![feature(lazy_cell)]

#[cfg(all(glutin, surfman, winit))]
compile_error!("You cannot specify both `glutin` and `surfman` features for winit window system");
Expand Down
2 changes: 1 addition & 1 deletion crates/emacs-sys/src/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ extern "C" {
) -> LispObject;
}

// In order to use `lazy_static!` with LispSubr, it must be Sync. Raw
// In order to use `LazyLock` with LispSubr, it must be Sync. Raw
// pointers are not Sync, but it isn't a problem to define Sync if we
// never mutate LispSubr values. If we do, we will need to create
// these objects at runtime, perhaps using forget().
Expand Down
11 changes: 5 additions & 6 deletions crates/emacs-sys/src/vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use libc::ptrdiff_t;
use std::mem;

use crate::bindings::VECTORP;
use lazy_static::lazy_static;

use crate::bindings::pvec_type;
use crate::bindings::Lisp_Type;
Expand All @@ -22,6 +21,7 @@ use crate::sys::Lisp_Vectorlike;
use crate::sys::PSEUDOVECTOR_FLAG;
use crate::terminal::TerminalRef;
use crate::window::WindowRef;
use std::sync::LazyLock;

pub type LispVectorlikeRef = ExternalPtr<Lisp_Vectorlike>;
#[allow(dead_code)]
Expand Down Expand Up @@ -236,11 +236,10 @@ macro_rules! impl_vectorlike_ref {

impl_vectorlike_ref! { LispVectorRef, LispVecIterator, ptrdiff_t::max_value() }

lazy_static! {
pub static ref HEADER_SIZE: usize =
memoffset::offset_of!(crate::bindings::Lisp_Vector, contents);
pub static ref WORD_SIZE: usize = ::std::mem::size_of::<crate::lisp::LispObject>();
}
pub static HEADER_SIZE: LazyLock<usize> =
LazyLock::new(|| memoffset::offset_of!(crate::bindings::Lisp_Vector, contents));
pub static WORD_SIZE: LazyLock<usize> =
LazyLock::new(|| ::std::mem::size_of::<crate::lisp::LispObject>());

pub trait LVector {
fn vectorp(self) -> bool;
Expand Down
1 change: 0 additions & 1 deletion crates/font/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ webrender_api.workspace = true
emacs-sys.path = "../emacs-sys"
lisp-macros.path = "../lisp-macros"
lisp-util.path = "../lisp-util"
lazy_static = "1.4"
log.workspace = true
libc.workspace = true
parking_lot.workspace = true
Expand Down
54 changes: 29 additions & 25 deletions crates/font/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![feature(concat_idents)]
#![feature(lazy_cell)]

#[macro_use]
extern crate emacs_sys;
Expand Down Expand Up @@ -31,7 +32,9 @@ use font_index::FontEntry;
pub use font_index::FontId;
use font_index::FontIndex;
use std::mem::ManuallyDrop;
use std::sync::OnceLock;
use std::sync::LazyLock;
use std::sync::Mutex;
use swash::shape::ShapeContext;
use swash::text::Language;
use swash::text::Script;
use swash::Attributes;
Expand Down Expand Up @@ -73,29 +76,32 @@ pub type FontRef = ExternalPtr<font>;
pub struct FontDriver(pub font_driver);
unsafe impl Sync for FontDriver {}

static FONT_DRIVER: OnceLock<FontDriver> = OnceLock::new();
static FONT_DRIVER: LazyLock<FontDriver> = LazyLock::new(|| {
log::trace!("FONT_DRIVER is being created...");
let mut font_driver = font_driver::default();

font_driver.type_ = Qswash;
font_driver.case_sensitive = true;
font_driver.get_cache = Some(get_cache);
font_driver.list = Some(list);
font_driver.match_ = Some(match_);
font_driver.list_family = Some(list_family);
font_driver.open_font = Some(open_font);
font_driver.close_font = Some(close_font);
font_driver.encode_char = Some(encode_char);
font_driver.has_char = Some(has_char);
font_driver.text_extents = Some(text_extents);
font_driver.draw = Some(draw);
font_driver.shape = Some(shape);

FontDriver(font_driver)
});
//shapecontext per thread
static SHAPE_CONTEXT: LazyLock<Mutex<ShapeContext>> =
LazyLock::new(|| Mutex::new(ShapeContext::new()));
impl FontDriver {
fn global() -> &'static FontDriver {
FONT_DRIVER.get_or_init(|| {
log::trace!("FONT_DRIVER is being created...");
let mut font_driver = font_driver::default();

font_driver.type_ = Qswash;
font_driver.case_sensitive = true;
font_driver.get_cache = Some(get_cache);
font_driver.list = Some(list);
font_driver.match_ = Some(match_);
font_driver.list_family = Some(list_family);
font_driver.open_font = Some(open_font);
font_driver.close_font = Some(close_font);
font_driver.encode_char = Some(encode_char);
font_driver.has_char = Some(has_char);
font_driver.text_extents = Some(text_extents);
font_driver.draw = Some(draw);
font_driver.shape = Some(shape);

FontDriver(font_driver)
})
&FONT_DRIVER
}
}

Expand Down Expand Up @@ -685,7 +691,6 @@ pub extern "C" fn shape(lgstring: LispObject, direction: LispObject) -> LispObje
use swash::shape::cluster::Glyph;
use swash::shape::cluster::GlyphCluster;
use swash::shape::Direction;
use swash::shape::ShapeContext;

let font = lgstring.lgstring_font();
let font = unsafe { CHECK_FONT_GET_OBJECT(font) };
Expand All @@ -711,8 +716,7 @@ pub extern "C" fn shape(lgstring: LispObject, direction: LispObject) -> LispObje
};
let source = source.as_str();

//TODO shapecontext per thread
let mut context = ShapeContext::new();
let mut context = SHAPE_CONTEXT.lock().expect("SHAPE_CONTEXT lock() failed");
let mut shaper_builder = context.builder(&font);

/* If the caller didn't provide a meaningful DIRECTION, let Swash
Expand Down
1 change: 0 additions & 1 deletion crates/git/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ openssl = { version = "0.10", features = ["vendored"] }
openssl-sys = { version = "0.9" }
git2 = "0.18"
libc.workspace = true
lazy_static.workspace = true

[build-dependencies]
codegen = { path = "../codegen" }
1 change: 1 addition & 0 deletions crates/git/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![feature(concat_idents)]
#![feature(lazy_cell)]

#[macro_use]
extern crate emacs_sys;
Expand Down
1 change: 0 additions & 1 deletion crates/js/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ lisp-macros.path = "../lisp-macros"
lisp-util.path = "../lisp-util"
lsp-json.path = "../lsp-json"
libc.workspace = true
lazy_static.workspace = true
futures = "0.3"
# deno_core = { git = "https://github.com/emacs-ng/deno", branch = "emacs-ng" }
# deno_runtime = { git = "https://github.com/emacs-ng/deno", branch = "emacs-ng" }
Expand Down
1 change: 1 addition & 0 deletions crates/js/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#![feature(concat_idents)]
#![feature(async_closure)]
#![feature(maybe_uninit_extra)]
#![feature(lazy_cell)]

extern crate futures;
extern crate serde_json;
Expand Down
1 change: 0 additions & 1 deletion crates/lisp-async/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ emacs-sys.path = "../emacs-sys"
lisp-macros.path = "../lisp-macros"
lisp-util.path = "../lisp-util"
libc.workspace = true
lazy_static.workspace = true
crossbeam = "0.8"
futures = "0.3"

Expand Down
1 change: 1 addition & 0 deletions crates/lisp-async/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![allow(non_camel_case_types, non_snake_case, non_upper_case_globals)]
#![feature(concat_idents)]
#![feature(async_closure)]
#![feature(lazy_cell)]

#[macro_use]
extern crate emacs_sys;
Expand Down
1 change: 0 additions & 1 deletion crates/lisp-doc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ edition = "2021"
lisp-util.path = "../lisp-util"
darling = "0.20"
anyhow = "1.0"
lazy_static.workspace = true
libc.workspace = true
regex.workspace = true

Expand Down
Loading

0 comments on commit cbf2d8f

Please sign in to comment.