Skip to content

Commit 4445c5a

Browse files
committed
refactor(fmt): replace Option::map_or(false, f) with is_some_and(f)
- Updated indentation calculation in FileLines to use is_some_and for tab and character checks, avoiding unnecessary computations and improving code flow. - Changed punctuation checks in WordSplit iterator to use is_some_and for cleaner, more idiomatic Rust code. - This refactor enhances readability and leverages short-circuiting behavior.
1 parent db77543 commit 4445c5a

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/uu/fmt/src/parasplit.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -188,16 +188,18 @@ impl FileLines<'_> {
188188
if idx >= prefix_end && !is_fmt_whitespace_byte(byte) {
189189
indent_end = idx;
190190
break;
191-
} else if byte == b'\t' {
191+
}
192+
193+
if byte == b'\t' {
192194
indent_len = (indent_len / self.opts.tabwidth + 1) * self.opts.tabwidth;
193195
idx += 1;
194196
continue;
195-
} else {
196-
let (ch, consumed) = decode_char(bytes, idx);
197-
indent_len += ch.map_or(1, char_width);
198-
idx += consumed;
199-
continue;
200197
}
198+
199+
let (ch, consumed) = decode_char(bytes, idx);
200+
indent_len += ch.map_or(1, char_width);
201+
idx += consumed;
202+
continue;
201203
}
202204
if indent_end == bytes.len() {
203205
indent_end = idx;
@@ -652,7 +654,7 @@ impl<'a> Iterator for WordSplit<'a> {
652654
let (ch, consumed) = decode_char(self.bytes, idx);
653655
let is_whitespace = ch
654656
.filter(|c| c.is_ascii())
655-
.map_or(false, |c| is_fmt_whitespace(c));
657+
.is_some_and(is_fmt_whitespace);
656658
if is_whitespace {
657659
break;
658660
}
@@ -676,7 +678,7 @@ impl<'a> Iterator for WordSplit<'a> {
676678
self.prev_punct && (before_tab.is_some() || word_start_relative > 1);
677679

678680
// now record whether this word ends in punctuation
679-
let ends_punct = last_ascii.map_or(false, WordSplit::is_punctuation_byte);
681+
let ends_punct = last_ascii.is_some_and(WordSplit::is_punctuation_byte);
680682
self.prev_punct = ends_punct;
681683

682684
let (word, word_start_relative, before_tab, after_tab) = if self.opts.uniform {

0 commit comments

Comments
 (0)