language: Add LanguageName::new_static to reduce allocations (#44380)
Implements a specialized constructor `LanguageName::new_static` for
`&'static str` which reduces allocations.
`LanguageName::new` always backs the underlying `SharedString` with an
owned `Arc<str>` even when a `&'static str` is passed. This makes us
allocate each time we create a new `LanguageName` no matter what.
Creating a specialized constructor for `&'static str` allows us to
essentially construct them for free.
Additional change:
Encourages using explicit constructors to avoid needless allocations.
Currently there were no instances of this trait being called where the
lifetime was not `'static` saving another 48 locations of allocation.
```rust
impl<'a> From<&'a str> for LanguageName {
fn from(str: &'a str) -> Self {
Self(SharedString::new(str))
}
}
// to
impl From<&'static str> for LanguageName {
fn from(str: &'static str) -> Self {
Self(SharedString::new_static(str))
}
}
```
Release Notes:
- N/A
This commit is contained in:
@@ -717,7 +717,7 @@ mod test {
|
||||
cx.update_global(|store: &mut SettingsStore, cx| {
|
||||
store.update_user_settings(cx, |settings| {
|
||||
settings.project.all_languages.languages.0.insert(
|
||||
LanguageName::new("Rust").0,
|
||||
LanguageName::new_static("Rust").0,
|
||||
LanguageSettingsContent {
|
||||
auto_indent_on_paste: Some(false),
|
||||
..Default::default()
|
||||
|
||||
Reference in New Issue
Block a user