Skip to content

Commit 22f663d

Browse files
committed
Update comments; Refactor 'len_utf8';
1 parent 7a0c167 commit 22f663d

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

library/core/src/char/methods.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -1736,14 +1736,11 @@ impl EscapeDebugExtArgs {
17361736

17371737
#[inline]
17381738
const fn len_utf8(code: u32) -> usize {
1739-
if code < MAX_ONE_B {
1740-
1
1741-
} else if code < MAX_TWO_B {
1742-
2
1743-
} else if code < MAX_THREE_B {
1744-
3
1745-
} else {
1746-
4
1739+
match code {
1740+
..MAX_ONE_B => 1,
1741+
..MAX_TWO_B => 2,
1742+
..MAX_THREE_B => 3,
1743+
_ => 4
17471744
}
17481745
}
17491746

@@ -1785,7 +1782,7 @@ pub const fn encode_utf8_raw(code: u32, dst: &mut [u8]) -> &mut [u8] {
17851782
*c = (code >> 6 & 0x3F) as u8 | TAG_CONT;
17861783
*d = (code & 0x3F) as u8 | TAG_CONT;
17871784
}
1788-
// Note that the original message is not const-compatible due to formatting.
1785+
// Note that we cannot format in constant expressions.
17891786
_ => panic!("encode_utf8: buffer does not have enough bytes to encode code point"),
17901787
};
17911788
// SAFETY: `<&mut [u8]>::as_mut_ptr` is guaranteed to return a valid pointer and `len` has been tested to be within bounds.

0 commit comments

Comments
 (0)