about summary refs log tree commit diff
path: root/src/rustllvm/RustWrapper.cpp
diff options
context:
space:
mode:
authorNicholas Nethercote <nnethercote@mozilla.com>2019-10-14 10:37:21 +1100
committerNicholas Nethercote <nnethercote@mozilla.com>2019-10-18 13:25:17 +1100
commita6eef299d3b0ca24f8ffc0c3dc03283c09ec7945 (patch)
tree7a238d968db0ddabfc1f517d3b1d8ea959bdc745 /src/rustllvm/RustWrapper.cpp
parentd0eaf60d5e4bd0d5be63a41ed9ff861dca95c932 (diff)
downloadrust-a6eef299d3b0ca24f8ffc0c3dc03283c09ec7945.tar.gz
rust-a6eef299d3b0ca24f8ffc0c3dc03283c09ec7945.zip
Make `TokenStream::from_iter` less general and more efficient.
The current code has this impl:
```
impl<T: Into<TokenStream>> iter::FromIterator<T> for TokenStream
```
If given an `IntoIterator<Item = TokenTree>`, it will convert each individual
`TokenTree` to a `TokenStream` (at the cost of two allocations: a `Vec`
and an `Lrc`). It will then merge those `TokenStream`s into a single
`TokenStream`. This is inefficient.

This commit changes the impl to this less general one:
```
impl iter::FromIterator<TokenTree> for TokenStream
```
It collects the `TokenTree`s into a single `Vec` first and then converts that
to a `TokenStream` by wrapping it in a single `Lrc`. The previous generality
was unnecessary; no other code needs changing.

This change speeds up several benchmarks by up to 4%.
Diffstat (limited to 'src/rustllvm/RustWrapper.cpp')
0 files changed, 0 insertions, 0 deletions