mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 11:20:54 +00:00
Merge pull request #19690 from ChayimFriedman2/preallocate-input
minor: Preallocate `parser::Input`
This commit is contained in:
commit
df594ba8f4
@ -12,7 +12,6 @@ type bits = u64;
|
|||||||
/// `Tokens` doesn't include whitespace and comments. Main input to the parser.
|
/// `Tokens` doesn't include whitespace and comments. Main input to the parser.
|
||||||
///
|
///
|
||||||
/// Struct of arrays internally, but this shouldn't really matter.
|
/// Struct of arrays internally, but this shouldn't really matter.
|
||||||
#[derive(Default)]
|
|
||||||
pub struct Input {
|
pub struct Input {
|
||||||
kind: Vec<SyntaxKind>,
|
kind: Vec<SyntaxKind>,
|
||||||
joint: Vec<bits>,
|
joint: Vec<bits>,
|
||||||
@ -21,6 +20,14 @@ pub struct Input {
|
|||||||
|
|
||||||
/// `pub` impl used by callers to create `Tokens`.
|
/// `pub` impl used by callers to create `Tokens`.
|
||||||
impl Input {
|
impl Input {
|
||||||
|
#[inline]
|
||||||
|
pub fn with_capacity(capacity: usize) -> Self {
|
||||||
|
Self {
|
||||||
|
kind: Vec::with_capacity(capacity),
|
||||||
|
joint: Vec::with_capacity(capacity / size_of::<bits>()),
|
||||||
|
contextual_kind: Vec::with_capacity(capacity),
|
||||||
|
}
|
||||||
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn push(&mut self, kind: SyntaxKind) {
|
pub fn push(&mut self, kind: SyntaxKind) {
|
||||||
self.push_impl(kind, SyntaxKind::EOF)
|
self.push_impl(kind, SyntaxKind::EOF)
|
||||||
|
@ -27,7 +27,7 @@ pub enum StrStep<'a> {
|
|||||||
impl LexedStr<'_> {
|
impl LexedStr<'_> {
|
||||||
pub fn to_input(&self, edition: Edition) -> crate::Input {
|
pub fn to_input(&self, edition: Edition) -> crate::Input {
|
||||||
let _p = tracing::info_span!("LexedStr::to_input").entered();
|
let _p = tracing::info_span!("LexedStr::to_input").entered();
|
||||||
let mut res = crate::Input::default();
|
let mut res = crate::Input::with_capacity(self.len());
|
||||||
let mut was_joint = false;
|
let mut was_joint = false;
|
||||||
for i in 0..self.len() {
|
for i in 0..self.len() {
|
||||||
let kind = self.kind(i);
|
let kind = self.kind(i);
|
||||||
|
@ -12,7 +12,7 @@ pub fn to_parser_input<Ctx: Copy + fmt::Debug + PartialEq + Eq + Hash>(
|
|||||||
buffer: tt::TokenTreesView<'_, SpanData<Ctx>>,
|
buffer: tt::TokenTreesView<'_, SpanData<Ctx>>,
|
||||||
span_to_edition: &mut dyn FnMut(Ctx) -> Edition,
|
span_to_edition: &mut dyn FnMut(Ctx) -> Edition,
|
||||||
) -> parser::Input {
|
) -> parser::Input {
|
||||||
let mut res = parser::Input::default();
|
let mut res = parser::Input::with_capacity(buffer.len());
|
||||||
|
|
||||||
let mut current = buffer.cursor();
|
let mut current = buffer.cursor();
|
||||||
let mut syntax_context_to_edition_cache = FxHashMap::default();
|
let mut syntax_context_to_edition_cache = FxHashMap::default();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user