summaryrefslogtreecommitdiff
path: root/crates/typst-library/src
diff options
context:
space:
mode:
authorAbdul-Rahman Sibahi <asibahi@users.noreply.github.com>2024-10-31 14:52:11 +0300
committerGitHub <noreply@github.com>2024-10-31 11:52:11 +0000
commitb969c01b282287b44c3e131f8c0c53dcbb304e30 (patch)
treefe58484bfa76e7fe7a35bf0bffdc339b24621693 /crates/typst-library/src
parent644ed252dda1a0785d2bee577a89322416f4d950 (diff)
Replace `once_cell`'s `Lazy` as much as possible (#4617)
Co-authored-by: Laurenz <laurmaedje@gmail.com>
Diffstat (limited to 'crates/typst-library/src')
-rw-r--r--crates/typst-library/src/foundations/element.rs6
-rw-r--r--crates/typst-library/src/foundations/func.rs9
-rw-r--r--crates/typst-library/src/foundations/mod.rs1
-rw-r--r--crates/typst-library/src/foundations/ty.rs6
-rw-r--r--crates/typst-library/src/model/bibliography.rs7
-rw-r--r--crates/typst-library/src/text/mod.rs4
-rw-r--r--crates/typst-library/src/text/raw.rs13
-rw-r--r--crates/typst-library/src/visualize/color.rs11
8 files changed, 27 insertions, 30 deletions
diff --git a/crates/typst-library/src/foundations/element.rs b/crates/typst-library/src/foundations/element.rs
index 8da71965..7ff00b9d 100644
--- a/crates/typst-library/src/foundations/element.rs
+++ b/crates/typst-library/src/foundations/element.rs
@@ -3,9 +3,9 @@ use std::cmp::Ordering;
use std::fmt::{self, Debug};
use std::hash::Hash;
use std::ptr::NonNull;
+use std::sync::LazyLock;
use ecow::EcoString;
-use once_cell::sync::Lazy;
use smallvec::SmallVec;
#[doc(inline)]
pub use typst_macros::elem;
@@ -292,9 +292,9 @@ pub struct NativeElementData {
pub field_from_styles: fn(u8, StyleChain) -> Result<Value, FieldAccessError>,
/// Gets the localized name for this element (see [`LocalName`][crate::text::LocalName]).
pub local_name: Option<fn(Lang, Option<Region>) -> &'static str>,
- pub scope: Lazy<Scope>,
+ pub scope: LazyLock<Scope>,
/// A list of parameter information for each field.
- pub params: Lazy<Vec<ParamInfo>>,
+ pub params: LazyLock<Vec<ParamInfo>>,
}
impl From<&'static NativeElementData> for Element {
diff --git a/crates/typst-library/src/foundations/func.rs b/crates/typst-library/src/foundations/func.rs
index 1b40714b..e34f48a1 100644
--- a/crates/typst-library/src/foundations/func.rs
+++ b/crates/typst-library/src/foundations/func.rs
@@ -2,11 +2,10 @@
pub use typst_macros::func;
use std::fmt::{self, Debug, Formatter};
-use std::sync::Arc;
+use std::sync::{Arc, LazyLock};
use comemo::{Tracked, TrackedMut};
use ecow::{eco_format, EcoString};
-use once_cell::sync::Lazy;
use typst_syntax::{ast, Span, SyntaxNode};
use typst_utils::{singleton, LazyHash, Static};
@@ -463,11 +462,11 @@ pub struct NativeFuncData {
pub keywords: &'static [&'static str],
/// Whether this function makes use of context.
pub contextual: bool,
- pub scope: Lazy<Scope>,
+ pub scope: LazyLock<Scope>,
/// A list of parameter information for each parameter.
- pub params: Lazy<Vec<ParamInfo>>,
+ pub params: LazyLock<Vec<ParamInfo>>,
/// Information about the return value of this function.
- pub returns: Lazy<CastInfo>,
+ pub returns: LazyLock<CastInfo>,
}
impl From<&'static NativeFuncData> for Func {
diff --git a/crates/typst-library/src/foundations/mod.rs b/crates/typst-library/src/foundations/mod.rs
index a6d6c253..9259a7d1 100644
--- a/crates/typst-library/src/foundations/mod.rs
+++ b/crates/typst-library/src/foundations/mod.rs
@@ -71,7 +71,6 @@ pub use typst_macros::{scope, ty};
pub use {
ecow::{eco_format, eco_vec},
indexmap::IndexMap,
- once_cell::sync::Lazy,
};
use ecow::EcoString;
diff --git a/crates/typst-library/src/foundations/ty.rs b/crates/typst-library/src/foundations/ty.rs
index 70845dd2..680c4f6a 100644
--- a/crates/typst-library/src/foundations/ty.rs
+++ b/crates/typst-library/src/foundations/ty.rs
@@ -3,9 +3,9 @@ pub use typst_macros::{scope, ty};
use std::cmp::Ordering;
use std::fmt::{self, Debug, Display, Formatter};
+use std::sync::LazyLock;
use ecow::{eco_format, EcoString};
-use once_cell::sync::Lazy;
use typst_utils::Static;
use crate::diag::StrResult;
@@ -207,8 +207,8 @@ pub struct NativeTypeData {
/// A list of alternate search terms for this type.
pub keywords: &'static [&'static str],
/// The constructor for this type.
- pub constructor: Lazy<Option<&'static NativeFuncData>>,
- pub scope: Lazy<Scope>,
+ pub constructor: LazyLock<Option<&'static NativeFuncData>>,
+ pub scope: LazyLock<Scope>,
}
impl From<&'static NativeTypeData> for Type {
diff --git a/crates/typst-library/src/model/bibliography.rs b/crates/typst-library/src/model/bibliography.rs
index d11055b9..56916731 100644
--- a/crates/typst-library/src/model/bibliography.rs
+++ b/crates/typst-library/src/model/bibliography.rs
@@ -4,7 +4,7 @@ use std::fmt::{self, Debug, Formatter};
use std::hash::{Hash, Hasher};
use std::num::NonZeroUsize;
use std::path::Path;
-use std::sync::Arc;
+use std::sync::{Arc, LazyLock};
use comemo::Tracked;
use ecow::{eco_format, EcoString, EcoVec};
@@ -15,7 +15,6 @@ use hayagriva::{
SpecificLocator,
};
use indexmap::IndexMap;
-use once_cell::sync::Lazy;
use smallvec::{smallvec, SmallVec};
use typed_arena::Arena;
use typst_syntax::{Span, Spanned};
@@ -633,8 +632,8 @@ impl<'a> Generator<'a> {
/// Drives hayagriva's citation driver.
fn drive(&mut self) -> hayagriva::Rendered {
- static LOCALES: Lazy<Vec<citationberg::Locale>> =
- Lazy::new(hayagriva::archive::locales);
+ static LOCALES: LazyLock<Vec<citationberg::Locale>> =
+ LazyLock::new(hayagriva::archive::locales);
let database = self.bibliography.bibliography();
let bibliography_style = self.bibliography.style(StyleChain::default());
diff --git a/crates/typst-library/src/text/mod.rs b/crates/typst-library/src/text/mod.rs
index acf100b5..6aeebbba 100644
--- a/crates/typst-library/src/text/mod.rs
+++ b/crates/typst-library/src/text/mod.rs
@@ -29,12 +29,12 @@ pub use self::smartquote::*;
pub use self::space::*;
use std::fmt::{self, Debug, Formatter};
+use std::sync::LazyLock;
use ecow::{eco_format, EcoString};
use icu_properties::sets::CodePointSetData;
use icu_provider::AsDeserializingBufferProvider;
use icu_provider_blob::BlobDataProvider;
-use once_cell::sync::Lazy;
use rustybuzz::Feature;
use smallvec::SmallVec;
use ttf_parser::Tag;
@@ -1275,7 +1275,7 @@ cast! {
/// Whether a codepoint is Unicode `Default_Ignorable`.
pub fn is_default_ignorable(c: char) -> bool {
/// The set of Unicode default ignorables.
- static DEFAULT_IGNORABLE_DATA: Lazy<CodePointSetData> = Lazy::new(|| {
+ static DEFAULT_IGNORABLE_DATA: LazyLock<CodePointSetData> = LazyLock::new(|| {
icu_properties::sets::load_default_ignorable_code_point(
&BlobDataProvider::try_new_from_static_blob(typst_assets::icu::ICU)
.unwrap()
diff --git a/crates/typst-library/src/text/raw.rs b/crates/typst-library/src/text/raw.rs
index 5ce77348..8691afcb 100644
--- a/crates/typst-library/src/text/raw.rs
+++ b/crates/typst-library/src/text/raw.rs
@@ -1,10 +1,9 @@
+use std::cell::LazyCell;
use std::hash::Hash;
use std::ops::Range;
-use std::sync::Arc;
+use std::sync::{Arc, LazyLock};
use ecow::{eco_format, EcoString, EcoVec};
-use once_cell::sync::Lazy;
-use once_cell::unsync::Lazy as UnsyncLazy;
use syntect::highlighting::{self as synt, Theme};
use syntect::parsing::{SyntaxDefinition, SyntaxSet, SyntaxSetBuilder};
use typst_syntax::{split_newlines, LinkedNode, Span, Spanned};
@@ -325,7 +324,7 @@ impl Packed<RawElem> {
.map(|s| s.to_lowercase())
.or(Some("txt".into()));
- let extra_syntaxes = UnsyncLazy::new(|| {
+ let extra_syntaxes = LazyCell::new(|| {
load_syntaxes(&elem.syntaxes(styles), &elem.syntaxes_data(styles)).unwrap()
});
let non_highlighted_result = |lines: EcoVec<(EcoString, Span)>| {
@@ -838,11 +837,11 @@ fn parse_theme(
///
/// Syntax set is generated from the syntaxes from the `bat` project
/// <https://github.com/sharkdp/bat/tree/master/assets/syntaxes>
-pub static RAW_SYNTAXES: Lazy<syntect::parsing::SyntaxSet> =
- Lazy::new(two_face::syntax::extra_no_newlines);
+pub static RAW_SYNTAXES: LazyLock<syntect::parsing::SyntaxSet> =
+ LazyLock::new(two_face::syntax::extra_no_newlines);
/// The default theme used for syntax highlighting.
-pub static RAW_THEME: Lazy<synt::Theme> = Lazy::new(|| synt::Theme {
+pub static RAW_THEME: LazyLock<synt::Theme> = LazyLock::new(|| synt::Theme {
name: Some("Typst Light".into()),
author: Some("The Typst Project Developers".into()),
settings: synt::ThemeSettings::default(),
diff --git a/crates/typst-library/src/visualize/color.rs b/crates/typst-library/src/visualize/color.rs
index 1a279fbb..8ff8dbdb 100644
--- a/crates/typst-library/src/visualize/color.rs
+++ b/crates/typst-library/src/visualize/color.rs
@@ -1,9 +1,9 @@
use std::fmt::{self, Debug, Formatter};
use std::hash::{Hash, Hasher};
use std::str::FromStr;
+use std::sync::LazyLock;
use ecow::{eco_format, EcoString, EcoVec};
-use once_cell::sync::Lazy;
use palette::encoding::{self, Linear};
use palette::{
Alpha, Darken, Desaturate, FromColor, Lighten, OklabHue, RgbHue, Saturate, ShiftHue,
@@ -33,17 +33,18 @@ pub type Luma = palette::luma::Lumaa<encoding::Srgb, f32>;
/// to convert from CMYK to RGB. It is based on the CGATS TR 001-1995
/// specification. See
/// <https://github.com/saucecontrol/Compact-ICC-Profiles#cmyk>.
-static CMYK_TO_XYZ: Lazy<Box<Profile>> =
- Lazy::new(|| Profile::new_from_slice(typst_assets::icc::CMYK_TO_XYZ, false).unwrap());
+static CMYK_TO_XYZ: LazyLock<Box<Profile>> = LazyLock::new(|| {
+ Profile::new_from_slice(typst_assets::icc::CMYK_TO_XYZ, false).unwrap()
+});
/// The target sRGB profile.
-static SRGB_PROFILE: Lazy<Box<Profile>> = Lazy::new(|| {
+static SRGB_PROFILE: LazyLock<Box<Profile>> = LazyLock::new(|| {
let mut out = Profile::new_sRGB();
out.precache_output_transform();
out
});
-static TO_SRGB: Lazy<qcms::Transform> = Lazy::new(|| {
+static TO_SRGB: LazyLock<qcms::Transform> = LazyLock::new(|| {
qcms::Transform::new_to(
&CMYK_TO_XYZ,
&SRGB_PROFILE,