Avoid allocating a string to compare language names

This commit is contained in:
Antonio Scandurra 2023-01-20 10:41:40 +01:00
parent c49dc8d6e5
commit 36e4dcef16
3 changed files with 5 additions and 1 deletions

1
Cargo.lock generated
View File

@ -3157,6 +3157,7 @@ dependencies = [
"tree-sitter-ruby",
"tree-sitter-rust",
"tree-sitter-typescript",
"unicase",
"unindent",
"util",
]

View File

@ -53,6 +53,7 @@ smol = "1.2"
tree-sitter = "0.20"
tree-sitter-rust = { version = "*", optional = true }
tree-sitter-typescript = { version = "*", optional = true }
unicase = "2.6"
[dev-dependencies]
client = { path = "../client", features = ["test-support"] }

View File

@ -41,6 +41,7 @@ use std::{
use syntax_map::SyntaxSnapshot;
use theme::{SyntaxTheme, Theme};
use tree_sitter::{self, Query};
use unicase::UniCase;
use util::ResultExt;
#[cfg(any(test, feature = "test-support"))]
@ -467,10 +468,11 @@ impl LanguageRegistry {
}
pub fn language_for_name(&self, name: &str) -> Option<Arc<Language>> {
let name = UniCase::new(name);
self.languages
.read()
.iter()
.find(|language| language.name().to_lowercase() == name.to_lowercase())
.find(|language| UniCase::new(language.name()) == name)
.cloned()
}