Skip to content

Commit 12ae365

Browse files
committed
Misc cleanups
1 parent f671242 commit 12ae365

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

src/libcore/fmt/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,7 +1076,7 @@ impl<'a> Formatter<'a> {
10761076
self.args[i].as_usize()
10771077
}
10781078
rt::v1::Count::NextParam => {
1079-
self.curarg.next().and_then(|arg| arg.as_usize())
1079+
self.curarg.next()?.as_usize()
10801080
}
10811081
}
10821082
}
@@ -1142,15 +1142,15 @@ impl<'a> Formatter<'a> {
11421142
sign = Some('+'); width += 1;
11431143
}
11441144

1145-
let mut prefixed = false;
1146-
if self.alternate() {
1147-
prefixed = true; width += prefix.chars().count();
1145+
let prefixed = self.alternate();
1146+
if prefixed {
1147+
width += prefix.chars().count();
11481148
}
11491149

11501150
// Writes the sign if it exists, and then the prefix if it was requested
11511151
let write_prefix = |f: &mut Formatter| {
11521152
if let Some(c) = sign {
1153-
f.buf.write_str(c.encode_utf8(&mut [0; 4]))?;
1153+
f.buf.write_char(c)?;
11541154
}
11551155
if prefixed { f.buf.write_str(prefix) }
11561156
else { Ok(()) }
@@ -1312,7 +1312,7 @@ impl<'a> Formatter<'a> {
13121312

13131313
// remove the sign from the formatted parts
13141314
formatted.sign = b"";
1315-
width = if width < sign.len() { 0 } else { width - sign.len() };
1315+
width = width.saturating_sub(sign.len());
13161316
align = rt::v1::Alignment::Right;
13171317
self.fill = '0';
13181318
self.align = rt::v1::Alignment::Right;

src/libcore/str/pattern.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,7 @@ impl<'a> Pattern<'a> for char {
425425
#[inline]
426426
fn into_searcher(self, haystack: &'a str) -> Self::Searcher {
427427
let mut utf8_encoded = [0; 4];
428-
self.encode_utf8(&mut utf8_encoded);
429-
let utf8_size = self.len_utf8();
428+
let utf8_size = self.encode_utf8(&mut utf8_encoded).len();
430429
CharSearcher {
431430
haystack,
432431
finger: 0,

0 commit comments

Comments
 (0)