Skip to content

Commit

Permalink
chore: remove once_cell (#912)
Browse files Browse the repository at this point in the history
  • Loading branch information
Brooooooklyn authored Oct 14, 2024
1 parent 9269e46 commit f791f86
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 13 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ napi = { version = "3.0.0-alpha.14", default-features = false, features
napi-derive = { version = "3.0.0-alpha.14", default-features = false }
nom = "7"
num_cpus = "1"
once_cell = "1"
regex = "1"
rgb = "0.8"
serde = "1"
Expand Down
6 changes: 3 additions & 3 deletions src/ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ use std::mem;
use std::result;
use std::slice;
use std::str::FromStr;
use std::sync::LazyLock;

use cssparser::{Color as CSSColor, Parser, ParserInput, RGBA};
use libavif::AvifData;
use napi::{bindgen_prelude::*, JsString, NapiRaw, NapiValue};
use once_cell::sync::Lazy;
use regex::Regex;

use crate::font::parse_size_px;
Expand All @@ -34,8 +34,8 @@ use crate::{
CanvasElement, SVGCanvas,
};

static CSS_SIZE_REGEXP: Lazy<Regex> =
Lazy::new(|| Regex::new(r#"(-?[\d\.]+)(%|px|pt|pc|in|cm|mm|%|em|ex|ch|rem|q)?\s*"#).unwrap());
static CSS_SIZE_REGEXP: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r#"(-?[\d\.]+)(%|px|pt|pc|in|cm|mm|%|em|ex|ch|rem|q)?\s*"#).unwrap());

impl From<SkError> for Error {
fn from(err: SkError) -> Error {
Expand Down
6 changes: 3 additions & 3 deletions src/font.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use std::str::FromStr;
use std::sync::OnceLock;

use once_cell::sync::OnceCell;
use regex::Regex;

use crate::error::SkError;

pub(crate) static FONT_REGEXP: OnceCell<Regex> = OnceCell::new();
pub(crate) static FONT_REGEXP: OnceLock<Regex> = OnceLock::new();

const DEFAULT_FONT: &str = "sans-serif";

Expand Down Expand Up @@ -122,7 +122,7 @@ pub(crate) fn init_font_regexp() -> Regex {
(small-caps|normal){0,1}\s+ | # variant
(bold|bolder|lighter|[1-9]00|normal){0,1}\s+ | # weight
(ultra-condensed|extra-condensed|condensed|semi-condensed|semi-expanded|expanded|extra-expanded|ultra-expanded|[\d\.]+%){0,1}\s+ # stretch
){0,4}
){0,4}
(
([\d\.]+) # size
(%|px|pt|pc|in|cm|mm|%|em|ex|ch|rem|q)?\s* # unit
Expand Down
10 changes: 4 additions & 6 deletions src/global_fonts.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use std::fs::read_dir;
use std::path;
use std::sync::{LockResult, Mutex, MutexGuard, PoisonError};

use once_cell::sync::{Lazy, OnceCell};
use std::sync::{LazyLock, LockResult, Mutex, MutexGuard, OnceLock, PoisonError};

use crate::sk::*;

Expand All @@ -15,10 +13,10 @@ const FONT_PATH: &str = "/usr/share/fonts/";
#[cfg(target_os = "android")]
const FONT_PATH: &str = "/system/fonts";

static FONT_DIR: OnceCell<napi::Result<u32>> = OnceCell::new();
static FONT_DIR: OnceLock<napi::Result<u32>> = OnceLock::new();

pub(crate) static GLOBAL_FONT_COLLECTION: Lazy<Mutex<FontCollection>> =
Lazy::new(|| Mutex::new(FontCollection::new()));
pub(crate) static GLOBAL_FONT_COLLECTION: LazyLock<Mutex<FontCollection>> =
LazyLock::new(|| Mutex::new(FontCollection::new()));

#[inline]
pub(crate) fn get_font<'a>() -> LockResult<MutexGuard<'a, FontCollection>> {
Expand Down

0 comments on commit f791f86

Please sign in to comment.