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>
This commit is contained in:
Hayashi Mikihiro 2024-08-15 01:20:54 +09:00 committed by GitHub
parent 7633bdccd2
commit ad85dd10e3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 17 additions and 22 deletions

1
Cargo.lock generated
View file

@ -1877,7 +1877,6 @@ dependencies = [
"freetype-sys",
"harfbuzz-sys",
"ipc-channel",
"lazy_static",
"libc",
"log",
"malloc_size_of",

View file

@ -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 }

View file

@ -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<FontList> = LazyLock::new(|| FontList::new());
/// An identifier for a local font on Android systems.
#[derive(Clone, Debug, Deserialize, Eq, Hash, MallocSizeOf, PartialEq, Serialize)]

View file

@ -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<FontList> = 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.

View file

@ -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<FontFuncs> = 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,