Skip to content

Commit 9e10161

Browse files
committed
lazy_staticをやめてonce_cellを使用するように修正
1 parent c0d7ef9 commit 9e10161

3 files changed

Lines changed: 13 additions & 10 deletions

File tree

atcoder-problems-backend/Cargo.lock

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

atcoder-problems-backend/sql-client/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ anyhow = "1.0"
1616
tokio = { version = "1.16", features = ["macros"] }
1717
regex = "1"
1818
chrono = "0.4"
19-
lazy_static = "1.4.0"
19+
once_cell = "1.12.0"

atcoder-problems-backend/sql-client/src/language_count.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@ use crate::models::{Submission, UserLanguageCount, UserLanguageCountRank, UserPr
22
use crate::{PgPool, MAX_INSERT_ROWS};
33
use anyhow::Result;
44
use async_trait::async_trait;
5-
use lazy_static::lazy_static;
6-
use regex::Regex;
75
use sqlx::postgres::PgRow;
86
use sqlx::Row;
97
use std::collections::{BTreeMap, BTreeSet};
108
use std::ops::Range;
119

10+
macro_rules! regex {
11+
($re:literal $(,)?) => {{
12+
static RE: once_cell::sync::OnceCell<regex::Regex> = once_cell::sync::OnceCell::new();
13+
RE.get_or_init(|| regex::Regex::new($re).unwrap())
14+
}};
15+
}
16+
1217
#[async_trait]
1318
pub trait LanguageCountClient {
1419
async fn update_language_count(
@@ -191,13 +196,11 @@ impl LanguageCountClient for PgPool {
191196
}
192197

193198
fn simplify_language(lang: &str) -> String {
194-
lazy_static! {
195-
static ref RE: Regex = Regex::new(r"\d*\s*\(.*\)").unwrap();
196-
}
199+
let re = regex!(r"\d*\s*\(.*\)");
197200
if lang.starts_with("Perl6") {
198201
"Raku".to_string()
199202
} else {
200-
RE.replace(lang, "").to_string()
203+
re.replace(lang, "").to_string()
201204
}
202205
}
203206

0 commit comments

Comments
 (0)