From ad85dd10e3aa6124e3f8a9504d9c6efa178b8d34 Mon Sep 17 00:00:00 2001 From: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com> Date: Thu, 15 Aug 2024 01:20:54 +0900 Subject: [PATCH] Replace lazy_static with std::sync::LazyLock in components/fonts (#33049) * replace in shaper.rs Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com> * replace in android/font_list.rs Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com> * replace in ohos/font_list.rs Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com> * remove lazy_lock from components/fonts Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com> --------- Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com> --- Cargo.lock | 1 - components/fonts/Cargo.toml | 1 - .../platform/freetype/android/font_list.rs | 5 ++-- .../fonts/platform/freetype/ohos/font_list.rs | 5 ++-- components/fonts/shaper.rs | 27 +++++++++---------- 5 files changed, 17 insertions(+), 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a0a4ed44084..ab7e7f51dd8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1877,7 +1877,6 @@ dependencies = [ "freetype-sys", "harfbuzz-sys", "ipc-channel", - "lazy_static", "libc", "log", "malloc_size_of", diff --git a/components/fonts/Cargo.toml b/components/fonts/Cargo.toml index 120e16037f4..8b976b4f9b8 100644 --- a/components/fonts/Cargo.toml +++ b/components/fonts/Cargo.toml @@ -25,7 +25,6 @@ fontsan = { git = "https://github.com/servo/fontsan" } fonts_traits = { workspace = true } harfbuzz-sys = "0.6.1" ipc-channel = { workspace = true } -lazy_static = { workspace = true } libc = { workspace = true } log = { workspace = true } malloc_size_of = { workspace = true } diff --git a/components/fonts/platform/freetype/android/font_list.rs b/components/fonts/platform/freetype/android/font_list.rs index b7152a8efc7..7f599041ce3 100644 --- a/components/fonts/platform/freetype/android/font_list.rs +++ b/components/fonts/platform/freetype/android/font_list.rs @@ -5,6 +5,7 @@ use std::fs::File; use std::io::Read; use std::path::Path; +use std::sync::LazyLock; use base::text::{is_cjk, UnicodeBlock, UnicodeBlockMethod}; use log::warn; @@ -21,9 +22,7 @@ use crate::{ FallbackFontSelectionOptions, FontTemplate, FontTemplateDescriptor, LowercaseFontFamilyName, }; -lazy_static::lazy_static! { - static ref FONT_LIST: FontList = FontList::new(); -} +static FONT_LIST: LazyLock = LazyLock::new(|| FontList::new()); /// An identifier for a local font on Android systems. #[derive(Clone, Debug, Deserialize, Eq, Hash, MallocSizeOf, PartialEq, Serialize)] diff --git a/components/fonts/platform/freetype/ohos/font_list.rs b/components/fonts/platform/freetype/ohos/font_list.rs index 1d210e1f3db..bc8303b78aa 100644 --- a/components/fonts/platform/freetype/ohos/font_list.rs +++ b/components/fonts/platform/freetype/ohos/font_list.rs @@ -7,6 +7,7 @@ use std::fs::File; use std::io::Read; use std::os::unix::ffi::OsStrExt; use std::path::{Path, PathBuf}; +use std::sync::LazyLock; use std::{fs, io}; use base::text::{UnicodeBlock, UnicodeBlockMethod}; @@ -25,9 +26,7 @@ use crate::{ FontTemplateDescriptor, LowercaseFontFamilyName, }; -lazy_static::lazy_static! { - static ref FONT_LIST: FontList = FontList::new(); -} +static FONT_LIST: LazyLock = LazyLock::new(|| FontList::new()); /// When testing the ohos font code on linux, we can pass the fonts directory of the SDK /// via an environment variable. diff --git a/components/fonts/shaper.rs b/components/fonts/shaper.rs index addd44d8b26..eb8f92b789d 100644 --- a/components/fonts/shaper.rs +++ b/components/fonts/shaper.rs @@ -5,6 +5,7 @@ #![allow(unsafe_code)] use std::os::raw::{c_char, c_int, c_uint, c_void}; +use std::sync::LazyLock; use std::{char, cmp, ptr}; use app_units::Au; @@ -24,7 +25,6 @@ use harfbuzz_sys::{ HB_OT_LAYOUT_BASELINE_TAG_HANGING, HB_OT_LAYOUT_BASELINE_TAG_IDEO_EMBOX_BOTTOM_OR_LEFT, HB_OT_LAYOUT_BASELINE_TAG_ROMAN, }; -use lazy_static::lazy_static; use log::debug; use crate::platform::font::FontTable; @@ -657,21 +657,20 @@ impl Shaper { struct FontFuncs(*mut hb_font_funcs_t); unsafe impl Sync for FontFuncs {} +unsafe impl Send for FontFuncs {} -lazy_static! { - static ref HB_FONT_FUNCS: FontFuncs = unsafe { - let hb_funcs = hb_font_funcs_create(); - hb_font_funcs_set_nominal_glyph_func(hb_funcs, Some(glyph_func), ptr::null_mut(), None); - hb_font_funcs_set_glyph_h_advance_func( - hb_funcs, - Some(glyph_h_advance_func), - ptr::null_mut(), - None, - ); +static HB_FONT_FUNCS: LazyLock = LazyLock::new(|| unsafe { + let hb_funcs = hb_font_funcs_create(); + hb_font_funcs_set_nominal_glyph_func(hb_funcs, Some(glyph_func), ptr::null_mut(), None); + hb_font_funcs_set_glyph_h_advance_func( + hb_funcs, + Some(glyph_h_advance_func), + ptr::null_mut(), + None, + ); - FontFuncs(hb_funcs) - }; -} + FontFuncs(hb_funcs) +}); extern "C" fn glyph_func( _: *mut hb_font_t,