core: optimise Debug impl for ascii::Char · patricklam/verify-rust-std@dc39cbf (original) (raw)

`@@ -3,7 +3,7 @@

`

3

3

`//! suggestions from rustc if you get anything slightly wrong in here, and overall

`

4

4

`` //! helps with clarity as we're also referring to char intentionally in here.

``

5

5

``

6

``

`-

use crate::fmt::{self, Write};

`

``

6

`+

use crate::fmt;

`

7

7

`use crate::mem::transmute;

`

8

8

``

9

9

`/// One of the 128 Unicode characters from U+0000 through U+007F,

`

`@@ -583,9 +583,10 @@ impl fmt::Display for AsciiChar {

`

583

583

`#[unstable(feature = "ascii_char", issue = "110998")]

`

584

584

`impl fmt::Debug for AsciiChar {

`

585

585

`fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {

`

586

``

`-

#[inline]

`

587

``

`-

fn backslash(a: AsciiChar) -> ([AsciiChar; 4], u8) {

`

588

``

`-

([AsciiChar::ReverseSolidus, a, AsciiChar::Null, AsciiChar::Null], 2)

`

``

586

`+

use AsciiChar::{Apostrophe, Null, ReverseSolidus as Backslash};

`

``

587

+

``

588

`+

fn backslash(a: AsciiChar) -> ([AsciiChar; 6], usize) {

`

``

589

`+

([Apostrophe, Backslash, a, Apostrophe, Null, Null], 4)

`

589

590

`}

`

590

591

``

591

592

`let (buf, len) = match self {

`

`@@ -595,24 +596,17 @@ impl fmt::Debug for AsciiChar {

`

595

596

`AsciiChar::LineFeed => backslash(AsciiChar::SmallN),

`

596

597

`AsciiChar::ReverseSolidus => backslash(AsciiChar::ReverseSolidus),

`

597

598

`AsciiChar::Apostrophe => backslash(AsciiChar::Apostrophe),

`

598

``

`-

_ => {

`

599

``

`-

let byte = self.to_u8();

`

600

``

`-

if !byte.is_ascii_control() {

`

601

``

`-

([*self, AsciiChar::Null, AsciiChar::Null, AsciiChar::Null], 1)

`

602

``

`-

} else {

`

603

``

`-

const HEX_DIGITS: [AsciiChar; 16] = *b"0123456789abcdef".as_ascii().unwrap();

`

``

599

`+

_ if self.to_u8().is_ascii_control() => {

`

``

600

`+

const HEX_DIGITS: [AsciiChar; 16] = *b"0123456789abcdef".as_ascii().unwrap();

`

604

601

``

605

``

`-

let hi = HEX_DIGITS[usize::from(byte >> 4)];

`

606

``

`-

let lo = HEX_DIGITS[usize::from(byte & 0xf)];

`

607

``

`-

([AsciiChar::ReverseSolidus, AsciiChar::SmallX, hi, lo], 4)

`

608

``

`-

}

`

``

602

`+

let byte = self.to_u8();

`

``

603

`+

let hi = HEX_DIGITS[usize::from(byte >> 4)];

`

``

604

`+

let lo = HEX_DIGITS[usize::from(byte & 0xf)];

`

``

605

`+

([Apostrophe, Backslash, AsciiChar::SmallX, hi, lo, Apostrophe], 6)

`

609

606

`}

`

``

607

`+

_ => ([Apostrophe, *self, Apostrophe, Null, Null, Null], 3),

`

610

608

`};

`

611

609

``

612

``

`-

f.write_char(''')?;

`

613

``

`-

for byte in &buf[..len as usize] {

`

614

``

`-

f.write_str(byte.as_str())?;

`

615

``

`-

}

`

616

``

`-

f.write_char(''')

`

``

610

`+

f.write_str(buf[..len].as_str())

`

617

611

`}

`

618

612

`}

`