Skip to content

uucore/build.rs: small refactoring#12250

Open
cakebaker wants to merge 1 commit into
uutils:mainfrom
cakebaker:uucore_build_rs_small_refactoring
Open

uucore/build.rs: small refactoring#12250
cakebaker wants to merge 1 commit into
uutils:mainfrom
cakebaker:uucore_build_rs_small_refactoring

Conversation

@cakebaker
Copy link
Copy Markdown
Contributor

No description provided.

@xtqqczze
Copy link
Copy Markdown
Contributor

I guess filter would be more idiomatic:

let system_locale = env
    .as_deref()
    .and_then(|s| s.split('.').next())
    .map(|s| s.replace('_', "-"))
    .filter(|s| !s.is_empty() && s != "en-US");

for better readability

Co-authored-by: xtqqczze <45661989+xtqqczze@users.noreply.github.com>
@cakebaker cakebaker force-pushed the uucore_build_rs_small_refactoring branch from ad5a140 to 720c557 Compare May 12, 2026 09:49
@cakebaker
Copy link
Copy Markdown
Contributor Author

Yes, I agree. I added you as a co-author.

@cakebaker cakebaker changed the title uucore/build.rs: use then_some instead of if/else uucore/build.rs: small refactoring May 12, 2026
Comment thread src/uucore/build.rs
let system_locale = env
.as_deref()
.and_then(|s| s.split('.').next())
.map(|s| s.replace('_', "-"))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In this case it's not worth the complexity, but in theory we could avoiding allocating for this kind of operation:

fn replace_underscores(s: &mut String) {
    // SAFETY:
    // '_' and '-' are both single-byte ASCII characters,
    // so this preserves UTF-8 validity and string length.
    unsafe {
        s.as_mut_vec()
            .iter_mut()
            .filter(|b| **b == b'_')
            .for_each(|b| *b = b'-');
    }
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In this case it's not worth the complexity

build.rs is not a production.

@github-actions
Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/rm/isatty (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/date/resolution (passes in this run but fails in the 'main' branch)
Congrats! The gnu test tests/tail/truncate is no longer failing!
Note: The gnu test tests/seq/seq-epipe is now being skipped but was previously passing.
Congrats! The gnu test tests/cut/bounded-memory is now passing!
Skip an intermittent issue tests/tail/tail-n0f (was skipped on 'main', now failing)

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.

3 participants