diff options
| author | Yuki Okushi <jtitor@2k36.org> | 2022-07-26 07:14:50 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-07-26 07:14:50 +0900 |
| commit | 5bbdf659965abf2bcc16b4d0f9e487ee570ba999 (patch) | |
| tree | 95ee6ee587744ec3703a8998c1d6c09fc6399f18 /compiler/rustc_codegen_gcc | |
| parent | 2973b00ca6bc85ba3552282657de81d4baf864cc (diff) | |
| parent | 63e74aba813d2e24ffa094d05c2545b5e882229f (diff) | |
| download | rust-5bbdf659965abf2bcc16b4d0f9e487ee570ba999.tar.gz rust-5bbdf659965abf2bcc16b4d0f9e487ee570ba999.zip | |
Rollup merge of #99703 - dtolnay:tokenstreamsizehint, r=petrochenkov
Expose size_hint() for TokenStream's iterator The iterator for `proc_macro::TokenStream` is a wrapper around a `Vec` iterator: https://github.com/rust-lang/rust/blob/babff2211e3ae9ef52852dc1b01f3eacdd94c12e/library/proc_macro/src/lib.rs#L363-L371 so it can cheaply provide a perfectly precise size hint, with just a pointer subtraction: https://github.com/rust-lang/rust/blob/babff2211e3ae9ef52852dc1b01f3eacdd94c12e/library/alloc/src/vec/into_iter.rs#L170-L177 I need the size hint in syn (https://github.com/dtolnay/syn/blob/1.0.98/src/buffer.rs) to reduce allocations when converting TokenStream into syn's internal TokenBuffer representation. Aside from `size_hint`, the other non-default methods in `std::vec::IntoIter`'s `Iterator` impl are `advance_by`, `count`, and `__iterator_get_unchecked`. I've included `count` in this PR since it is trivial. I did not include `__iterator_get_unchecked` because it is spoopy and I did not feel like dealing with that. Lastly, I did not include `advance_by` because that requires `feature(iter_advance_by)` (https://github.com/rust-lang/rust/issues/77404) and I noticed this comment at the top of libproc_macro: https://github.com/rust-lang/rust/blob/babff2211e3ae9ef52852dc1b01f3eacdd94c12e/library/proc_macro/src/lib.rs#L20-L22
Diffstat (limited to 'compiler/rustc_codegen_gcc')
0 files changed, 0 insertions, 0 deletions
