[librsvg: 1/3] Replace lazy_static with once_cell
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 1/3] Replace lazy_static with once_cell
- Date: Sun, 10 Nov 2019 20:13:06 +0000 (UTC)
commit 1fcb7fd6a4ddd8cd89699ef4a4184605d1b952e0
Author: Paolo Borelli <pborelli gnome org>
Date: Fri Nov 8 22:55:47 2019 +0100
Replace lazy_static with once_cell
Cargo.lock | 8 +-
rsvg_internals/Cargo.toml | 2 +-
rsvg_internals/src/create_node.rs | 184 +++++++++++++++++++-------------------
rsvg_internals/src/link.rs | 6 +-
rsvg_internals/src/log.rs | 6 +-
5 files changed, 103 insertions(+), 103 deletions(-)
---
diff --git a/Cargo.lock b/Cargo.lock
index 7ad512da..4cb45672 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -724,6 +724,11 @@ dependencies = [
"objc 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
]
+[[package]]
+name = "once_cell"
+version = "1.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
[[package]]
name = "pango"
version = "0.7.0"
@@ -1122,12 +1127,12 @@ dependencies = [
"glib-sys 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"itertools 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
"language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)",
"locale_config 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"markup5ever 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
"nalgebra 0.18.1 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
+ "once_cell 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"pango 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"pango-sys 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"pangocairo 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1459,6 +1464,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum objc 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" =
"915b1b472bc21c53464d6c8461c9d3af805ba1ef837e1cac254428f4a77177b1"
"checksum objc-foundation 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" =
"1add1b659e36c9607c7aab864a76c7a4c2760cd0cd2e120f3fb8b952c7e22bf9"
"checksum objc_id 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" =
"c92d4ddb4bd7b50d730c215ff871754d0da6b2178849f8a2a2ab69712d0c073b"
+"checksum once_cell 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" =
"891f486f630e5c5a4916c7e16c4b24a53e78c860b646e9f8e005e4f16847bfed"
"checksum pango 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" =
"393fa071b144f8ffb83ede273758983cf414ca3c0b1d2a5a9ce325b3ba3dd786"
"checksum pango-sys 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" =
"1ee97abcad820f9875e032656257ad1c790e7b11a0e6ce2516a8f5b0d8f8213f"
"checksum pangocairo 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" =
"7486695787f206924b662cb8ca7b3c987fdbbff4ccff3612017cf471aee65162"
diff --git a/rsvg_internals/Cargo.toml b/rsvg_internals/Cargo.toml
index c87f1fd6..aa00f6f1 100644
--- a/rsvg_internals/Cargo.toml
+++ b/rsvg_internals/Cargo.toml
@@ -22,12 +22,12 @@ glib = { version="0.8.0" }
glib-sys = "0.9.0"
itertools = "0.8"
language-tags = "0.2.2"
-lazy_static = "1.0.0"
libc = "0.2"
locale_config = "*" # recommended explicitly by locale_config's README.md
markup5ever = "0.10"
nalgebra = "0.18"
num-traits = "0.2"
+once_cell = "1.2.0"
pango = "0.7.0"
pango-sys = "0.9.0"
pangocairo = "0.8.0"
diff --git a/rsvg_internals/src/create_node.rs b/rsvg_internals/src/create_node.rs
index fee05e2a..0e345a01 100644
--- a/rsvg_internals/src/create_node.rs
+++ b/rsvg_internals/src/create_node.rs
@@ -1,5 +1,5 @@
-use lazy_static::lazy_static;
use markup5ever::{expanded_name, local_name, namespace_url, ns, QualName};
+use once_cell::sync::Lazy;
use std::collections::HashMap;
use crate::clip_path::ClipPath;
@@ -133,98 +133,96 @@ macro_rules! c {
};
}
-lazy_static! {
- // Lines in comments are elements that we don't support.
- #[cfg_attr(rustfmt, rustfmt_skip)]
- static ref NODE_CREATORS: HashMap<&'static str, (bool, NodeCreateFn)> = {
- let mut h = HashMap::new();
- // name, supports_class, create_fn
- c!(h, "a", true, create_link);
- /* c!(h, "altGlyph", true, ); */
- /* c!(h, "altGlyphDef", false, ); */
- /* c!(h, "altGlyphItem", false, ); */
- /* c!(h, "animate", false, ); */
- /* c!(h, "animateColor", false, ); */
- /* c!(h, "animateMotion", false, ); */
- /* c!(h, "animateTransform", false, ); */
- c!(h, "circle", true, create_circle);
- c!(h, "clipPath", true, create_clip_path);
- /* c!(h, "color-profile", false, ); */
- /* c!(h, "cursor", false, ); */
- c!(h, "defs", true, create_defs);
- /* c!(h, "desc", true, ); */
- c!(h, "ellipse", true, create_ellipse);
- c!(h, "feBlend", true, create_fe_blend);
- c!(h, "feColorMatrix", true, create_fe_color_matrix);
- c!(h, "feComponentTransfer", true, create_fe_component_transfer);
- c!(h, "feComposite", true, create_fe_composite);
- c!(h, "feConvolveMatrix", true, create_fe_convolve_matrix);
- c!(h, "feDiffuseLighting", true, create_fe_diffuse_lighting);
- c!(h, "feDisplacementMap", true, create_fe_displacement_map);
- c!(h, "feDistantLight", false, create_fe_distant_light);
- c!(h, "feFuncA", false, create_fe_func_a);
- c!(h, "feFuncB", false, create_fe_func_b);
- c!(h, "feFuncG", false, create_fe_func_g);
- c!(h, "feFuncR", false, create_fe_func_r);
- c!(h, "feFlood", true, create_fe_flood);
- c!(h, "feGaussianBlur", true, create_fe_gaussian_blur);
- c!(h, "feImage", true, create_fe_image);
- c!(h, "feMerge", true, create_fe_merge);
- c!(h, "feMergeNode", false, create_fe_merge_node);
- c!(h, "feMorphology", true, create_fe_morphology);
- c!(h, "feOffset", true, create_fe_offset);
- c!(h, "fePointLight", false, create_fe_point_light);
- c!(h, "feSpecularLighting", true, create_fe_specular_lighting);
- c!(h, "feSpotLight", false, create_fe_spot_light);
- c!(h, "feTile", true, create_fe_tile);
- c!(h, "feTurbulence", true, create_fe_turbulence);
- c!(h, "filter", true, create_filter);
- /* c!(h, "font", true, ); */
- /* c!(h, "font-face", false, ); */
- /* c!(h, "font-face-format", false, ); */
- /* c!(h, "font-face-name", false, ); */
- /* c!(h, "font-face-src", false, ); */
- /* c!(h, "font-face-uri", false, ); */
- /* c!(h, "foreignObject", true, ); */
- c!(h, "g", true, create_group);
- /* c!(h, "glyph", true, ); */
- /* c!(h, "glyphRef", true, ); */
- /* c!(h, "hkern", false, ); */
- c!(h, "image", true, create_image);
- c!(h, "line", true, create_line);
- c!(h, "linearGradient", true, create_linear_gradient);
- c!(h, "marker", true, create_marker);
- c!(h, "mask", true, create_mask);
- /* c!(h, "metadata", false, ); */
- /* c!(h, "missing-glyph", true, ); */
- /* c!(h, "mpath", false, ); */
- /* c!(h, "multiImage", false, create_multi_image); */
- c!(h, "path", true, create_path);
- c!(h, "pattern", true, create_pattern);
- c!(h, "polygon", true, create_polygon);
- c!(h, "polyline", true, create_polyline);
- c!(h, "radialGradient", true, create_radial_gradient);
- c!(h, "rect", true, create_rect);
- /* c!(h, "script", false, ); */
- /* c!(h, "set", false, ); */
- c!(h, "stop", true, create_stop);
- c!(h, "style", false, create_style);
- /* c!(h, "subImage", false, create_sub_image); */
- /* c!(h, "subImageRef", false, create_sub_image_ref); */
- c!(h, "svg", true, create_svg);
- c!(h, "switch", true, create_switch);
- c!(h, "symbol", true, create_symbol);
- c!(h, "text", true, create_text);
- /* c!(h, "textPath", true, ); */
- /* c!(h, "title", true, ); */
- c!(h, "tref", true, create_tref);
- c!(h, "tspan", true, create_tspan);
- c!(h, "use", true, create_use);
- /* c!(h, "view", false, ); */
- /* c!(h, "vkern", false, ); */
- h
- };
-}
+// Lines in comments are elements that we don't support.
+#[cfg_attr(rustfmt, rustfmt_skip)]
+static NODE_CREATORS: Lazy<HashMap<&'static str, (bool, NodeCreateFn)>> = Lazy::new(|| {
+ let mut h = HashMap::new();
+ // name, supports_class, create_fn
+ c!(h, "a", true, create_link);
+ /* c!(h, "altGlyph", true, ); */
+ /* c!(h, "altGlyphDef", false, ); */
+ /* c!(h, "altGlyphItem", false, ); */
+ /* c!(h, "animate", false, ); */
+ /* c!(h, "animateColor", false, ); */
+ /* c!(h, "animateMotion", false, ); */
+ /* c!(h, "animateTransform", false, ); */
+ c!(h, "circle", true, create_circle);
+ c!(h, "clipPath", true, create_clip_path);
+ /* c!(h, "color-profile", false, ); */
+ /* c!(h, "cursor", false, ); */
+ c!(h, "defs", true, create_defs);
+ /* c!(h, "desc", true, ); */
+ c!(h, "ellipse", true, create_ellipse);
+ c!(h, "feBlend", true, create_fe_blend);
+ c!(h, "feColorMatrix", true, create_fe_color_matrix);
+ c!(h, "feComponentTransfer", true, create_fe_component_transfer);
+ c!(h, "feComposite", true, create_fe_composite);
+ c!(h, "feConvolveMatrix", true, create_fe_convolve_matrix);
+ c!(h, "feDiffuseLighting", true, create_fe_diffuse_lighting);
+ c!(h, "feDisplacementMap", true, create_fe_displacement_map);
+ c!(h, "feDistantLight", false, create_fe_distant_light);
+ c!(h, "feFuncA", false, create_fe_func_a);
+ c!(h, "feFuncB", false, create_fe_func_b);
+ c!(h, "feFuncG", false, create_fe_func_g);
+ c!(h, "feFuncR", false, create_fe_func_r);
+ c!(h, "feFlood", true, create_fe_flood);
+ c!(h, "feGaussianBlur", true, create_fe_gaussian_blur);
+ c!(h, "feImage", true, create_fe_image);
+ c!(h, "feMerge", true, create_fe_merge);
+ c!(h, "feMergeNode", false, create_fe_merge_node);
+ c!(h, "feMorphology", true, create_fe_morphology);
+ c!(h, "feOffset", true, create_fe_offset);
+ c!(h, "fePointLight", false, create_fe_point_light);
+ c!(h, "feSpecularLighting", true, create_fe_specular_lighting);
+ c!(h, "feSpotLight", false, create_fe_spot_light);
+ c!(h, "feTile", true, create_fe_tile);
+ c!(h, "feTurbulence", true, create_fe_turbulence);
+ c!(h, "filter", true, create_filter);
+ /* c!(h, "font", true, ); */
+ /* c!(h, "font-face", false, ); */
+ /* c!(h, "font-face-format", false, ); */
+ /* c!(h, "font-face-name", false, ); */
+ /* c!(h, "font-face-src", false, ); */
+ /* c!(h, "font-face-uri", false, ); */
+ /* c!(h, "foreignObject", true, ); */
+ c!(h, "g", true, create_group);
+ /* c!(h, "glyph", true, ); */
+ /* c!(h, "glyphRef", true, ); */
+ /* c!(h, "hkern", false, ); */
+ c!(h, "image", true, create_image);
+ c!(h, "line", true, create_line);
+ c!(h, "linearGradient", true, create_linear_gradient);
+ c!(h, "marker", true, create_marker);
+ c!(h, "mask", true, create_mask);
+ /* c!(h, "metadata", false, ); */
+ /* c!(h, "missing-glyph", true, ); */
+ /* c!(h, "mpath", false, ); */
+ /* c!(h, "multiImage", false, create_multi_image); */
+ c!(h, "path", true, create_path);
+ c!(h, "pattern", true, create_pattern);
+ c!(h, "polygon", true, create_polygon);
+ c!(h, "polyline", true, create_polyline);
+ c!(h, "radialGradient", true, create_radial_gradient);
+ c!(h, "rect", true, create_rect);
+ /* c!(h, "script", false, ); */
+ /* c!(h, "set", false, ); */
+ c!(h, "stop", true, create_stop);
+ c!(h, "style", false, create_style);
+ /* c!(h, "subImage", false, create_sub_image); */
+ /* c!(h, "subImageRef", false, create_sub_image_ref); */
+ c!(h, "svg", true, create_svg);
+ c!(h, "switch", true, create_switch);
+ c!(h, "symbol", true, create_symbol);
+ c!(h, "text", true, create_text);
+ /* c!(h, "textPath", true, ); */
+ /* c!(h, "title", true, ); */
+ c!(h, "tref", true, create_tref);
+ c!(h, "tspan", true, create_tspan);
+ c!(h, "use", true, create_use);
+ /* c!(h, "view", false, ); */
+ /* c!(h, "vkern", false, ); */
+ h
+});
pub fn create_node(name: &QualName, pbag: &PropertyBag) -> RsvgNode {
let mut id = None;
diff --git a/rsvg_internals/src/link.rs b/rsvg_internals/src/link.rs
index a903a18e..0ad5b6d6 100644
--- a/rsvg_internals/src/link.rs
+++ b/rsvg_internals/src/link.rs
@@ -1,5 +1,5 @@
-use lazy_static::lazy_static;
use markup5ever::{expanded_name, local_name, namespace_url, ns};
+use once_cell::sync::Lazy;
use regex::{Captures, Regex};
use std::borrow::Cow;
@@ -59,9 +59,7 @@ impl NodeTrait for Link {
/// escape quotes and backslashes with backslash
fn escape_value(value: &str) -> Cow<'_, str> {
- lazy_static! {
- static ref REGEX: Regex = Regex::new(r"['\\]").unwrap();
- }
+ static REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"['\\]").unwrap());
REGEX.replace_all(value, |caps: &Captures<'_>| {
match caps.get(0).unwrap().as_str() {
diff --git a/rsvg_internals/src/log.rs b/rsvg_internals/src/log.rs
index 6956dea2..f004a312 100644
--- a/rsvg_internals/src/log.rs
+++ b/rsvg_internals/src/log.rs
@@ -1,4 +1,4 @@
-use lazy_static::lazy_static;
+use once_cell::sync::Lazy;
#[macro_export]
macro_rules! rsvg_log {
@@ -12,9 +12,7 @@ macro_rules! rsvg_log {
}
pub fn log_enabled() -> bool {
- lazy_static! {
- static ref ENABLED: bool = ::std::env::var_os("RSVG_LOG").is_some();
- }
+ static ENABLED: Lazy<bool> = Lazy::new(|| ::std::env::var_os("RSVG_LOG").is_some());
*ENABLED
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]