Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use std LazyLock instead of once_cell Lazy #6529

Merged
merged 3 commits into from
Aug 27, 2024
Merged

Use std LazyLock instead of once_cell Lazy #6529

merged 3 commits into from
Aug 27, 2024

Conversation

dlon
Copy link
Member

@dlon dlon commented Jul 29, 2024

The container needs to be updated to use Rust 1.80 before this can be merged.


This change is Reviewable

@dlon dlon force-pushed the update-lazy-types branch from 398619a to e5e78a3 Compare July 29, 2024 10:06
Copy link
Contributor

@MarkusPettersson98 MarkusPettersson98 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed all commit messages.
Reviewable status: 0 of 52 files reviewed, 1 unresolved discussion (waiting on @dlon)


talpid-core/src/firewall/linux.rs line 62 at r1 (raw file):

    LazyLock::new(|| CString::new("prerouting").unwrap());
static MANGLE_CHAIN_NAME: LazyLock<CString> = LazyLock::new(|| CString::new("mangle").unwrap());
static NAT_CHAIN_NAME: LazyLock<CString> = LazyLock::new(|| CString::new("nat").unwrap());

Nit: I think these uses of LazyLock could fairly easily be replaced by swapping to &CStr

static TABLE_NAME: &CStr = c"mullvad";
static IN_CHAIN_NAME: &CStr = c"input";
static OUT_CHAIN_NAME: &CStr = c"output";
static FORWARD_CHAIN_NAME: &CStr = c"forward";
static PREROUTING_CHAIN_NAME: &CStr = c"prerouting";
static MANGLE_CHAIN_NAME: &CStr = c"mangle";
static NAT_CHAIN_NAME: &CStr = c"nat";

Might apply for other uses of static CStrings as well

Code quote:

static TABLE_NAME: LazyLock<CString> = LazyLock::new(|| CString::new("mullvad").unwrap());
static IN_CHAIN_NAME: LazyLock<CString> = LazyLock::new(|| CString::new("input").unwrap());
static OUT_CHAIN_NAME: LazyLock<CString> = LazyLock::new(|| CString::new("output").unwrap());
static FORWARD_CHAIN_NAME: LazyLock<CString> = LazyLock::new(|| CString::new("forward").unwrap());
static PREROUTING_CHAIN_NAME: LazyLock<CString> =
    LazyLock::new(|| CString::new("prerouting").unwrap());
static MANGLE_CHAIN_NAME: LazyLock<CString> = LazyLock::new(|| CString::new("mangle").unwrap());
static NAT_CHAIN_NAME: LazyLock<CString> = LazyLock::new(|| CString::new("nat").unwrap());

@dlon dlon force-pushed the update-lazy-types branch 2 times, most recently from a57e37f to 6d4a301 Compare July 30, 2024 14:03
Copy link
Member Author

@dlon dlon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 54 files reviewed, all discussions resolved


talpid-core/src/firewall/linux.rs line 62 at r1 (raw file):

Previously, MarkusPettersson98 (Markus Pettersson) wrote…

Nit: I think these uses of LazyLock could fairly easily be replaced by swapping to &CStr

static TABLE_NAME: &CStr = c"mullvad";
static IN_CHAIN_NAME: &CStr = c"input";
static OUT_CHAIN_NAME: &CStr = c"output";
static FORWARD_CHAIN_NAME: &CStr = c"forward";
static PREROUTING_CHAIN_NAME: &CStr = c"prerouting";
static MANGLE_CHAIN_NAME: &CStr = c"mangle";
static NAT_CHAIN_NAME: &CStr = c"nat";

Might apply for other uses of static CStrings as well

Great idea!

@dlon dlon force-pushed the update-lazy-types branch from 6d4a301 to 5a9ef35 Compare July 30, 2024 14:07
@dlon dlon force-pushed the update-lazy-types branch from 5a9ef35 to 26fc4f2 Compare August 26, 2024 20:04
@dlon dlon marked this pull request as ready for review August 26, 2024 20:04
Copy link
Contributor

@MarkusPettersson98 MarkusPettersson98 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 27 of 52 files at r1, 31 of 31 files at r2, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @dlon)


talpid-wireguard/src/lib.rs line 16 at r2 (raw file):

use std::io;
#[cfg(target_os = "linux")]
use std::sync::LazyLock;

Nit The Linux-specific imports could be grouped to reduce visual clutter a bit

#[cfg(target_os = "linux")]
use std::{env, sync::LazyLock};
#[cfg(windows)]
use std::io;

Code quote:

#[cfg(target_os = "linux")]
use std::env;
#[cfg(windows)]
use std::io;
#[cfg(target_os = "linux")]
use std::sync::LazyLock;

Copy link
Contributor

@MarkusPettersson98 MarkusPettersson98 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 1 files at r3, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

@dlon dlon force-pushed the update-lazy-types branch from c6ca867 to cd409ea Compare August 27, 2024 08:24
@dlon dlon merged commit fcd755a into main Aug 27, 2024
61 of 62 checks passed
@dlon dlon deleted the update-lazy-types branch August 27, 2024 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants