summaryrefslogtreecommitdiff
path: root/crates/typst-layout
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-layout
parent644ed252dda1a0785d2bee577a89322416f4d950 (diff)
Replace `once_cell`'s `Lazy` as much as possible (#4617)
Co-authored-by: Laurenz <laurmaedje@gmail.com>
Diffstat (limited to 'crates/typst-layout')
-rw-r--r--crates/typst-layout/Cargo.toml1
-rw-r--r--crates/typst-layout/src/flow/block.rs11
-rw-r--r--crates/typst-layout/src/flow/collect.rs5
-rw-r--r--crates/typst-layout/src/inline/box.rs7
-rw-r--r--crates/typst-layout/src/inline/linebreak.rs10
-rw-r--r--crates/typst-layout/src/transforms.rs5
6 files changed, 20 insertions, 19 deletions
diff --git a/crates/typst-layout/Cargo.toml b/crates/typst-layout/Cargo.toml
index 4c133a4e..438e09e4 100644
--- a/crates/typst-layout/Cargo.toml
+++ b/crates/typst-layout/Cargo.toml
@@ -30,7 +30,6 @@ icu_provider_adapters = { workspace = true }
icu_provider_blob = { workspace = true }
icu_segmenter = { workspace = true }
kurbo = { workspace = true }
-once_cell = { workspace = true }
rustybuzz = { workspace = true }
smallvec = { workspace = true }
ttf-parser = { workspace = true }
diff --git a/crates/typst-layout/src/flow/block.rs b/crates/typst-layout/src/flow/block.rs
index 48ca1fba..71eacc1c 100644
--- a/crates/typst-layout/src/flow/block.rs
+++ b/crates/typst-layout/src/flow/block.rs
@@ -1,4 +1,5 @@
-use once_cell::unsync::Lazy;
+use std::cell::LazyCell;
+
use smallvec::SmallVec;
use typst_library::diag::SourceResult;
use typst_library::engine::Engine;
@@ -79,8 +80,8 @@ pub fn layout_single_block(
.map(|s| s.map(Stroke::unwrap_or_default));
// Only fetch these if necessary (for clipping or filling/stroking).
- let outset = Lazy::new(|| elem.outset(styles).unwrap_or_default());
- let radius = Lazy::new(|| elem.radius(styles).unwrap_or_default());
+ let outset = LazyCell::new(|| elem.outset(styles).unwrap_or_default());
+ let radius = LazyCell::new(|| elem.radius(styles).unwrap_or_default());
// Clip the contents, if requested.
if elem.clip(styles) {
@@ -194,8 +195,8 @@ pub fn layout_multi_block(
.map(|s| s.map(Stroke::unwrap_or_default));
// Only fetch these if necessary (for clipping or filling/stroking).
- let outset = Lazy::new(|| elem.outset(styles).unwrap_or_default());
- let radius = Lazy::new(|| elem.radius(styles).unwrap_or_default());
+ let outset = LazyCell::new(|| elem.outset(styles).unwrap_or_default());
+ let radius = LazyCell::new(|| elem.radius(styles).unwrap_or_default());
// Fetch/compute these outside of the loop.
let clip = elem.clip(styles);
diff --git a/crates/typst-layout/src/flow/collect.rs b/crates/typst-layout/src/flow/collect.rs
index aee5d508..d3974349 100644
--- a/crates/typst-layout/src/flow/collect.rs
+++ b/crates/typst-layout/src/flow/collect.rs
@@ -1,11 +1,10 @@
-use std::cell::RefCell;
+use std::cell::{LazyCell, RefCell};
use std::fmt::{self, Debug, Formatter};
use std::hash::Hash;
use bumpalo::boxed::Box as BumpBox;
use bumpalo::Bump;
use comemo::{Track, Tracked, TrackedMut};
-use once_cell::unsync::Lazy;
use typst_library::diag::{bail, SourceResult};
use typst_library::engine::{Engine, Route, Sink, Traced};
use typst_library::foundations::{Packed, Resolve, Smart, StyleChain};
@@ -182,7 +181,7 @@ impl<'a> Collector<'a, '_, '_> {
_ => None,
};
- let fallback = Lazy::new(|| ParElem::spacing_in(styles));
+ let fallback = LazyCell::new(|| ParElem::spacing_in(styles));
let spacing = |amount| match amount {
Smart::Auto => Child::Rel((*fallback).into(), 4),
Smart::Custom(Spacing::Rel(rel)) => Child::Rel(rel.resolve(styles), 3),
diff --git a/crates/typst-layout/src/inline/box.rs b/crates/typst-layout/src/inline/box.rs
index 62054bea..6dfbc969 100644
--- a/crates/typst-layout/src/inline/box.rs
+++ b/crates/typst-layout/src/inline/box.rs
@@ -1,4 +1,5 @@
-use once_cell::unsync::Lazy;
+use std::cell::LazyCell;
+
use typst_library::diag::SourceResult;
use typst_library::engine::Engine;
use typst_library::foundations::{Packed, StyleChain};
@@ -56,8 +57,8 @@ pub fn layout_box(
.map(|s| s.map(Stroke::unwrap_or_default));
// Only fetch these if necessary (for clipping or filling/stroking).
- let outset = Lazy::new(|| elem.outset(styles).unwrap_or_default());
- let radius = Lazy::new(|| elem.radius(styles).unwrap_or_default());
+ let outset = LazyCell::new(|| elem.outset(styles).unwrap_or_default());
+ let radius = LazyCell::new(|| elem.radius(styles).unwrap_or_default());
// Clip the contents, if requested.
if elem.clip(styles) {
diff --git a/crates/typst-layout/src/inline/linebreak.rs b/crates/typst-layout/src/inline/linebreak.rs
index 7fc8b368..26621cd7 100644
--- a/crates/typst-layout/src/inline/linebreak.rs
+++ b/crates/typst-layout/src/inline/linebreak.rs
@@ -1,4 +1,5 @@
use std::ops::{Add, Sub};
+use std::sync::LazyLock;
use az::SaturatingAs;
use icu_properties::maps::{CodePointMapData, CodePointMapDataBorrowed};
@@ -7,7 +8,6 @@ use icu_provider::AsDeserializingBufferProvider;
use icu_provider_adapters::fork::ForkByKeyProvider;
use icu_provider_blob::BlobDataProvider;
use icu_segmenter::LineSegmenter;
-use once_cell::sync::Lazy;
use typst_library::engine::Engine;
use typst_library::layout::{Abs, Em};
use typst_library::model::Linebreaks;
@@ -40,11 +40,11 @@ fn blob() -> BlobDataProvider {
}
/// The general line break segmenter.
-static SEGMENTER: Lazy<LineSegmenter> =
- Lazy::new(|| LineSegmenter::try_new_lstm_with_buffer_provider(&blob()).unwrap());
+static SEGMENTER: LazyLock<LineSegmenter> =
+ LazyLock::new(|| LineSegmenter::try_new_lstm_with_buffer_provider(&blob()).unwrap());
/// The line break segmenter for Chinese/Japanese text.
-static CJ_SEGMENTER: Lazy<LineSegmenter> = Lazy::new(|| {
+static CJ_SEGMENTER: LazyLock<LineSegmenter> = LazyLock::new(|| {
let cj_blob =
BlobDataProvider::try_new_from_static_blob(typst_assets::icu::ICU_CJ_SEGMENT)
.unwrap();
@@ -53,7 +53,7 @@ static CJ_SEGMENTER: Lazy<LineSegmenter> = Lazy::new(|| {
});
/// The Unicode line break properties for each code point.
-static LINEBREAK_DATA: Lazy<CodePointMapData<LineBreak>> = Lazy::new(|| {
+static LINEBREAK_DATA: LazyLock<CodePointMapData<LineBreak>> = LazyLock::new(|| {
icu_properties::maps::load_line_break(&blob().as_deserializing()).unwrap()
});
diff --git a/crates/typst-layout/src/transforms.rs b/crates/typst-layout/src/transforms.rs
index 5ac9f777..e0f29c4c 100644
--- a/crates/typst-layout/src/transforms.rs
+++ b/crates/typst-layout/src/transforms.rs
@@ -1,4 +1,5 @@
-use once_cell::unsync::Lazy;
+use std::cell::LazyCell;
+
use typst_library::diag::{bail, SourceResult};
use typst_library::engine::Engine;
use typst_library::foundations::{Content, Packed, Resolve, Smart, StyleChain};
@@ -113,7 +114,7 @@ fn resolve_scale(
})
}
- let size = Lazy::new(|| {
+ let size = LazyCell::new(|| {
let pod = Region::new(container, Axes::splat(false));
let frame = crate::layout_frame(engine, &elem.body, locator, styles, pod)?;
SourceResult::Ok(frame.size())