From d4b135f38c8c0050768c50e62043ddca5f09079a Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 21 Dec 2019 18:45:46 +0100 Subject: Optimize and profile --- crates/ra_ide/src/inlay_hints.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/inlay_hints.rs b/crates/ra_ide/src/inlay_hints.rs index 3154df457..c5e406977 100644 --- a/crates/ra_ide/src/inlay_hints.rs +++ b/crates/ra_ide/src/inlay_hints.rs @@ -1,12 +1,15 @@ //! FIXME: write short doc here -use crate::{db::RootDatabase, FileId}; use hir::{HirDisplay, SourceAnalyzer}; +use once_cell::unsync::Lazy; +use ra_prof::profile; use ra_syntax::{ ast::{self, AstNode, TypeAscriptionOwner}, match_ast, SmolStr, SourceFile, SyntaxKind, SyntaxNode, TextRange, }; +use crate::{db::RootDatabase, FileId}; + #[derive(Debug, PartialEq, Eq)] pub enum InlayKind { TypeHint, @@ -27,7 +30,7 @@ pub(crate) fn inlay_hints( ) -> Vec { file.syntax() .descendants() - .map(|node| get_inlay_hints(db, file_id, &node, max_inlay_hint_length).unwrap_or_default()) + .flat_map(|node| get_inlay_hints(db, file_id, &node, max_inlay_hint_length)) .flatten() .collect() } @@ -38,7 +41,9 @@ fn get_inlay_hints( node: &SyntaxNode, max_inlay_hint_length: Option, ) -> Option> { - let analyzer = SourceAnalyzer::new(db, hir::InFile::new(file_id.into(), node), None); + let _p = profile("get_inlay_hints"); + let analyzer = + Lazy::new(|| SourceAnalyzer::new(db, hir::InFile::new(file_id.into(), node), None)); match_ast! { match node { ast::LetStmt(it) => { -- cgit v1.2.3