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

Clean up and streamline the pretty-printer #56336

Merged
merged 4 commits into from Nov 30, 2018

Commits on Nov 29, 2018

  1. Fix whitespace in pp.rs.

    This commit converts some 2-space indents to 4-space indents.
    nnethercote committed Nov 29, 2018
    Copy the full SHA
    6c80f7c View commit details
    Browse the repository at this point in the history
  2. Remove huge_word and zero_word.

    They are unused. The commit also adds some blank lines between some
    methods.
    nnethercote committed Nov 29, 2018
    Copy the full SHA
    deb9195 View commit details
    Browse the repository at this point in the history
  3. Use Cow in Token::String.

    `Printer::word` takes a `&str` and converts it into a `String`, which
    causes an allocation. But that allocation is rarely necessary, because
    `&str` is almost always a `&'static str` or a `String` that won't be
    used again.
    
    This commit changes `Token::String` so it holds a `Cow<'static, str>`
    instead of a `String`, which avoids a lot of allocations.
    nnethercote committed Nov 29, 2018
    Copy the full SHA
    787959c View commit details
    Browse the repository at this point in the history
  4. Split up pretty_print and print.

    `pretty_print` takes a `Token` and `match`es on it. But the particular
    `Token` kind is known at each call site, so this commit splits it into
    five functions: `pretty_print_eof`, `pretty_print_begin`, etc.
    
    This commit also does likewise with `print`, though there is one
    callsite for `print` where the `Token` kind isn't known, so a generic
    `print` has to stay (but it now just calls out to the various `print_*`
    functions).
    nnethercote committed Nov 29, 2018
    Copy the full SHA
    64cd645 View commit details
    Browse the repository at this point in the history