Rollup merge of #89015 - klensy:escape-def, r=Mark-Simulacrum
core::ascii::escape_default: reduce struct size
This commit is contained in:
commit
051168b876
@ -21,7 +21,7 @@
|
|||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct EscapeDefault {
|
pub struct EscapeDefault {
|
||||||
range: Range<usize>,
|
range: Range<u8>,
|
||||||
data: [u8; 4],
|
data: [u8; 4],
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,7 +114,7 @@ fn hexify(b: u8) -> u8 {
|
|||||||
impl Iterator for EscapeDefault {
|
impl Iterator for EscapeDefault {
|
||||||
type Item = u8;
|
type Item = u8;
|
||||||
fn next(&mut self) -> Option<u8> {
|
fn next(&mut self) -> Option<u8> {
|
||||||
self.range.next().map(|i| self.data[i])
|
self.range.next().map(|i| self.data[i as usize])
|
||||||
}
|
}
|
||||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||||
self.range.size_hint()
|
self.range.size_hint()
|
||||||
@ -126,7 +126,7 @@ fn last(mut self) -> Option<u8> {
|
|||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl DoubleEndedIterator for EscapeDefault {
|
impl DoubleEndedIterator for EscapeDefault {
|
||||||
fn next_back(&mut self) -> Option<u8> {
|
fn next_back(&mut self) -> Option<u8> {
|
||||||
self.range.next_back().map(|i| self.data[i])
|
self.range.next_back().map(|i| self.data[i as usize])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
@ -138,7 +138,9 @@ impl FusedIterator for EscapeDefault {}
|
|||||||
impl fmt::Display for EscapeDefault {
|
impl fmt::Display for EscapeDefault {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
// SAFETY: ok because `escape_default` created only valid utf-8 data
|
// SAFETY: ok because `escape_default` created only valid utf-8 data
|
||||||
f.write_str(unsafe { from_utf8_unchecked(&self.data[self.range.clone()]) })
|
f.write_str(unsafe {
|
||||||
|
from_utf8_unchecked(&self.data[(self.range.start as usize)..(self.range.end as usize)])
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user