Skip to content

Commit a7364ac

Browse files
committed
wc: introduce IS_POSIXLY_CORRECT static
1 parent b7e967c commit a7364ac

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/uu/wc/src/wc.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use std::{
1919
io::{self, Write, stderr},
2020
iter,
2121
path::{Path, PathBuf},
22+
sync::LazyLock,
2223
};
2324

2425
use clap::{Arg, ArgAction, ArgMatches, Command, builder::ValueParser};
@@ -579,11 +580,11 @@ fn process_chunk<
579580
text: &str,
580581
current_len: &mut usize,
581582
in_word: &mut bool,
582-
posixly_correct: bool,
583+
is_posixly_correct: bool,
583584
) {
584585
for ch in text.chars() {
585586
if SHOW_WORDS {
586-
let is_space = if posixly_correct {
587+
let is_space = if is_posixly_correct {
587588
matches!(ch, '\t'..='\r' | ' ')
588589
} else {
589590
ch.is_whitespace()
@@ -655,7 +656,7 @@ fn word_count_from_reader_specialized<
655656
let mut reader = BufReadDecoder::new(reader.buffered());
656657
let mut in_word = false;
657658
let mut current_len = 0;
658-
let posixly_correct = env::var_os("POSIXLY_CORRECT").is_some();
659+
let is_posixly_correct = IS_POSIXLY_CORRECT;
659660
while let Some(chunk) = reader.next_strict() {
660661
match chunk {
661662
Ok(text) => {
@@ -664,7 +665,7 @@ fn word_count_from_reader_specialized<
664665
text,
665666
&mut current_len,
666667
&mut in_word,
667-
posixly_correct,
668+
is_posixly_correct,
668669
);
669670
}
670671
Err(e) => {
@@ -1039,3 +1040,6 @@ fn print_stats(
10391040
}
10401041
writeln!(stdout)
10411042
}
1043+
1044+
static IS_POSIXLY_CORRECT: LazyLock<bool> =
1045+
LazyLock::new(|| env::var_os("POSIXLY_CORRECT").is_some());

0 commit comments

Comments
 (0)