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

Remove unnecessary range replacements #128224

Merged
merged 4 commits into from
Jul 27, 2024

Commits on Jul 26, 2024

  1. Don't include inner attribute ranges in CaptureState.

    The current code is this:
    ```
    self.capture_state.replace_ranges.push((start_pos..end_pos, Some(target)));
    self.capture_state.replace_ranges.extend(inner_attr_replace_ranges);
    ```
    What's not obvious is that every range in `inner_attr_replace_ranges`
    must be a strict sub-range of `start_pos..end_pos`. Which means, in
    `LazyAttrTokenStreamImpl::to_attr_token_stream`, they will be done
    first, and then the `start_pos..end_pos` replacement will just overwrite
    them. So they aren't needed.
    nnethercote committed Jul 26, 2024
    Configuration menu
    Copy the full SHA
    a560810 View commit details
    Browse the repository at this point in the history
  2. Fix a comment.

    Imagine you have replace ranges (2..20,X) and (5..15,Y), and these tokens:
    ```
    a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x
    ```
    If we replace (5..15,Y) first, then (2..20,X) we get this sequence
    ```
    a,b,c,d,e,Y,_,_,_,_,_,_,_,_,_,p,q,r,s,t,u,v,w,x
    a,b,X,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,u,v,w,x
    ```
    which is what we want.
    
    If we do it in the other order, we get this:
    ```
    a,b,X,_,_,_,_,_,_,_,_,_,_,_,_,p,q,r,s,t,u,v,w,x
    a,b,X,_,_,Y,_,_,_,_,_,_,_,_,_,_,_,_,_,_,u,v,w,x
    ```
    which is wrong. So it's true that we need the `.rev()` but the comment
    is wrong about why.
    nnethercote committed Jul 26, 2024
    Configuration menu
    Copy the full SHA
    6e87858 View commit details
    Browse the repository at this point in the history
  3. Tweak a loop.

    A fully imperative style is easier to read than a half-iterator,
    half-imperative style. Also, rename `inner_attr` as `attr` because it
    might be an outer attribute.
    nnethercote committed Jul 26, 2024
    Configuration menu
    Copy the full SHA
    6ea2da5 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    55d37ae View commit details
    Browse the repository at this point in the history