Skip to content

Commit 56974fd

Browse files
committed
move off once_cell
1 parent 14696de commit 56974fd

13 files changed

Lines changed: 27 additions & 37 deletions

File tree

Cargo.lock

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

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ publish.workspace = true
5757
[dependencies]
5858
anyhow = { version = "1.0.97", features = ["backtrace"] }
5959
log = "0.4.27"
60-
once_cell = "1"
6160
pretty-hex = "0.4.1"
6261
smoltcp = "0.12"
6362
tokio = { version = "1.44.1", features = ["macros", "net", "rt-multi-thread", "sync", "time", "io-util", "process"] }

mitmproxy-contentviews/src/grpc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{Metadata, Prettify, Protobuf, Reencode};
2-
use mitmproxy_highlight::Language;
32
use anyhow::{bail, Context, Result};
3+
use mitmproxy_highlight::Language;
44
use serde::Deserialize;
55
use serde_yaml::Value;
66

mitmproxy-contentviews/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ mod protobuf;
66

77
use anyhow::Result;
88

9-
use mitmproxy_highlight::Language;
109
pub use grpc::GRPC;
1110
pub use hex_dump::HexDump;
1211
pub use hex_stream::HexStream;
12+
use mitmproxy_highlight::Language;
1313
pub use msgpack::MsgPack;
1414
pub use protobuf::Protobuf;
1515

mitmproxy-contentviews/src/msgpack.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::{Metadata, Prettify, Reencode};
2-
use mitmproxy_highlight::Language;
32
use anyhow::{Context, Result};
3+
use mitmproxy_highlight::Language;
44
use rmp_serde::{decode, encode};
55

66
pub struct MsgPack;

mitmproxy-contentviews/src/protobuf.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{Metadata, Prettify, Reencode};
2-
use mitmproxy_highlight::Language;
32
use anyhow::{bail, Context, Result};
3+
use mitmproxy_highlight::Language;
44
use protobuf::descriptor::field_descriptor_proto::Label::LABEL_REPEATED;
55
use protobuf::descriptor::field_descriptor_proto::Type;
66
use protobuf::descriptor::field_descriptor_proto::Type::{
@@ -24,9 +24,9 @@ use std::ops::Deref;
2424
use std::str::FromStr;
2525

2626
mod tags {
27-
use std::sync::LazyLock;
2827
use regex::Regex;
2928
use serde_yaml::value::Tag;
29+
use std::sync::LazyLock;
3030

3131
pub(super) static BINARY: LazyLock<Tag> = LazyLock::new(|| Tag::new("binary"));
3232
pub(super) static VARINT: LazyLock<Tag> = LazyLock::new(|| Tag::new("varint"));

mitmproxy-highlight/benches/syntax_highlight.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,7 @@ fn criterion_benchmark(c: &mut Criterion) {
2525

2626
let data = "<a>x".repeat(8096);
2727
c.bench_function("syntax_highlight xml", |b| {
28-
b.iter(|| {
29-
Language::Xml
30-
.highlight(black_box(data.as_bytes()))
31-
.unwrap()
32-
})
28+
b.iter(|| Language::Xml.highlight(black_box(data.as_bytes())).unwrap())
3329
});
3430

3531
// tree_sitter_html is faster, but not by orders of magnitude.

mitmproxy-rs/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ mitmproxy-contentviews = { path = "../mitmproxy-contentviews" }
2222
anyhow = { version = "1.0.97", features = ["backtrace"] }
2323
data-encoding = "2.8.0"
2424
log = "0.4.27"
25-
once_cell = "1"
2625
pyo3 = { version = "0.24", features = ["abi3", "abi3-py312", "anyhow"] }
2726
pyo3-async-runtimes = { version = "0.24", features = ["tokio-runtime", "testing", "attributes"] }
2827
pyo3-log = "0.12"

mitmproxy-rs/src/dns_resolver.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use mitmproxy::dns::{ResolveError, DNS_SERVERS};
2-
use once_cell::sync::OnceCell;
32
use pyo3::exceptions::socket::gaierror;
43
use pyo3::prelude::*;
54
use pyo3::types::PyAny;
5+
use std::sync::OnceLock;
66
use std::{net::IpAddr, net::SocketAddr, sync::Arc};
77

88
/// A DNS resolver backed by [hickory-dns](https://github.com/hickory-dns/hickory-dns).
@@ -78,10 +78,10 @@ pub fn get_system_dns_servers() -> PyResult<Vec<String>> {
7878
})
7979
}
8080

81-
struct AddrInfoErrorConst(&'static str, OnceCell<isize>);
81+
struct AddrInfoErrorConst(&'static str, OnceLock<isize>);
8282
impl AddrInfoErrorConst {
8383
const fn new(identifier: &'static str) -> Self {
84-
AddrInfoErrorConst(identifier, OnceCell::new())
84+
AddrInfoErrorConst(identifier, OnceLock::new())
8585
}
8686
fn get(&self) -> isize {
8787
*self.1.get_or_init(|| {

mitmproxy-rs/src/lib.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
extern crate core;
22

3-
use std::sync::RwLock;
3+
use std::sync::{LazyLock, Mutex};
44

55
use crate::contentview::{Contentview, InteractiveContentview};
66
use mitmproxy_contentviews::{Prettify, Reencode};
7-
use once_cell::sync::Lazy;
87
use pyo3::{exceptions::PyException, prelude::*};
98

109
mod contentview;
@@ -17,15 +16,15 @@ pub mod task;
1716
mod udp_client;
1817
mod util;
1918

20-
static LOGGER_INITIALIZED: Lazy<RwLock<bool>> = Lazy::new(|| RwLock::new(false));
19+
static LOGGER_INITIALIZED: LazyLock<Mutex<bool>> = LazyLock::new(|| Mutex::new(false));
2120

2221
fn init_logger() -> PyResult<()> {
23-
if *LOGGER_INITIALIZED.read().unwrap() {
22+
if *LOGGER_INITIALIZED.lock().unwrap() {
2423
// logger already initialized
2524
Ok(())
2625
} else if pyo3_log::try_init().is_ok() {
2726
// logger successfully initialized
28-
*LOGGER_INITIALIZED.write().unwrap() = true;
27+
*LOGGER_INITIALIZED.lock().unwrap() = true;
2928
Ok(())
3029
} else {
3130
// logger was not initialized and could not be initialized

0 commit comments

Comments
 (0)