Skip to content

Commit e0aa475

Browse files
sayrerclaude
andcommitted
Replace lazy_static JSON parsing with LazyLock and struct literals.
Static configs are now constructed directly as Rust values instead of parsing embedded JSON strings at runtime. Removes the lazy_static dependency in favor of std::sync::LazyLock. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 59b290b commit e0aa475

File tree

4 files changed

+40
-15
lines changed

4 files changed

+40
-15
lines changed

rust/Cargo.lock

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/config/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ rust_library(
1313
"src/v3.json",
1414
],
1515
deps = [
16-
"//3rdparty/crates:lazy_static",
1716
"//3rdparty/crates:serde",
1817
"//3rdparty/crates:serde_json",
1918
],

rust/config/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ repository = "https://github.com/sayrer/twitter-text"
99
edition = "2018"
1010

1111
[dependencies]
12-
lazy_static = "1.1.0"
1312
serde = "1.0.104"
1413
serde_derive = "1.0.104"
1514
serde_json = "1.0.45"

rust/config/src/lib.rs

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Licensed under the Apache License, Version 2.0
33
// http://www.apache.org/licenses/LICENSE-2.0
44

5-
use lazy_static::lazy_static;
65
use serde::de::{self, Deserialize, Deserializer, MapAccess, Visitor};
76
use serde::ser::{Serialize, SerializeStruct, Serializer};
87
use serde_derive::{Deserialize, Serialize};
@@ -11,6 +10,7 @@ use std::fmt;
1110
use std::fs::File;
1211
use std::io::Read;
1312
use std::path::PathBuf;
13+
use std::sync::LazyLock;
1414

1515
pub const DEFAULT_VERSION: i32 = 3;
1616
pub const DEFAULT_WEIGHTED_LENGTH: i32 = 280;
@@ -21,11 +21,45 @@ pub const V1_JSON: &str = include_str!("v1.json");
2121
pub const V2_JSON: &str = include_str!("v2.json");
2222
pub const V3_JSON: &str = include_str!("v3.json");
2323

24-
lazy_static! {
25-
static ref CONFIG_V1: Configuration = Configuration::configuration_from_json(V1_JSON);
26-
static ref CONFIG_V2: Configuration = Configuration::configuration_from_json(V2_JSON);
27-
static ref CONFIG_V3: Configuration = Configuration::configuration_from_json(V3_JSON);
28-
}
24+
static CONFIG_V1: LazyLock<Configuration> = LazyLock::new(|| Configuration {
25+
version: 1,
26+
max_weighted_tweet_length: 140,
27+
scale: 1,
28+
default_weight: 1,
29+
transformed_url_length: 23,
30+
ranges: vec![],
31+
emoji_parsing_enabled: false,
32+
});
33+
34+
static CONFIG_V2: LazyLock<Configuration> = LazyLock::new(|| Configuration {
35+
version: 2,
36+
max_weighted_tweet_length: 280,
37+
scale: 100,
38+
default_weight: 200,
39+
transformed_url_length: 23,
40+
ranges: vec![
41+
WeightedRange::new(0, 4351, 100),
42+
WeightedRange::new(8192, 8205, 100),
43+
WeightedRange::new(8208, 8223, 100),
44+
WeightedRange::new(8242, 8247, 100),
45+
],
46+
emoji_parsing_enabled: false,
47+
});
48+
49+
static CONFIG_V3: LazyLock<Configuration> = LazyLock::new(|| Configuration {
50+
version: 3,
51+
max_weighted_tweet_length: 280,
52+
scale: 100,
53+
default_weight: 200,
54+
transformed_url_length: 23,
55+
ranges: vec![
56+
WeightedRange::new(0, 4351, 100),
57+
WeightedRange::new(8192, 8205, 100),
58+
WeightedRange::new(8208, 8223, 100),
59+
WeightedRange::new(8242, 8247, 100),
60+
],
61+
emoji_parsing_enabled: true,
62+
});
2963

3064
pub extern "C" fn config_v1() -> &'static Configuration {
3165
&CONFIG_V1

0 commit comments

Comments
 (0)