Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor core::char::EscapeDefault and co. structures #105076

Merged
merged 3 commits into from
May 2, 2023
Merged

Commits on Apr 5, 2023

  1. Refactor core::char::EscapeDefault and co. structures

    Change core::char::{EscapeUnicode, EscapeDefault and EscapeDebug}
    structures from using a state machine to computing escaped sequence
    upfront and during iteration just going through the characters.
    
    This is arguably simpler since it’s easier to think about having
    a buffer and start..end range to iterate over rather than thinking
    about a state machine.
    
    This also harmonises implementation of aforementioned iterators and
    core::ascii::EscapeDefault struct.  This is done by introducing a new
    helper EscapeIterInner struct which holds the buffer and offers simple
    methods for iterating over range.
    
    As a side effect, this probably optimises Display implementation for
    those types since rather than calling write_char repeatedly, write_str
    is invoked once.  On 64-bit platforms, it also reduces size of some of
    the structs:
    
        | Struct                     | Before | After |
        |----------------------------+--------+-------+
        | core::char::EscapeUnicode  |     16 |    12 |
        | core::char::EscapeDefault  |     16 |    12 |
        | core::char::EscapeDebug    |     16 |    16 |
    
    My ulterior motive and reason why I started looking into this is
    addition of as_str method to the iterators.  With this change this
    will became trivial.  It’s also going to be trivial to implement
    DoubleEndedIterator if that’s ever desired.
    mina86 committed Apr 5, 2023
    Configuration menu
    Copy the full SHA
    4510439 View commit details
    Browse the repository at this point in the history

Commits on Apr 30, 2023

  1. review

    mina86 committed Apr 30, 2023
    Configuration menu
    Copy the full SHA
    4d0f7e2 View commit details
    Browse the repository at this point in the history
  2. a bit more usize::from

    mina86 committed Apr 30, 2023
    Configuration menu
    Copy the full SHA
    76c9947 View commit details
    Browse the repository at this point in the history