diff options
| author | Jonas Schievink <jonas.schievink@ferrous-systems.com> | 2022-07-06 19:49:05 +0200 |
|---|---|---|
| committer | Jonas Schievink <jonas.schievink@ferrous-systems.com> | 2022-07-06 19:49:05 +0200 |
| commit | d2fd137252236d71bd5c8983e6ab2af6ff59e8e2 (patch) | |
| tree | e5e3501935e7ba02917d1efc4a962cb313c927a0 | |
| parent | 00194ade760caebed8e992d2b2931d6bae688438 (diff) | |
| download | rust-d2fd137252236d71bd5c8983e6ab2af6ff59e8e2.tar.gz rust-d2fd137252236d71bd5c8983e6ab2af6ff59e8e2.zip | |
Use `SmallVec` to slightly shrink `ModPath` size
| -rw-r--r-- | Cargo.lock | 1 | ||||
| -rw-r--r-- | crates/hir-expand/Cargo.toml | 1 | ||||
| -rw-r--r-- | crates/hir-expand/src/mod_path.rs | 7 |
3 files changed, 6 insertions, 3 deletions
diff --git a/Cargo.lock b/Cargo.lock index 69e27d2e81b..fceaa0797c4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -532,6 +532,7 @@ dependencies = [ "mbe", "profile", "rustc-hash", + "smallvec", "stdx", "syntax", "tracing", diff --git a/crates/hir-expand/Cargo.toml b/crates/hir-expand/Cargo.toml index 453afa6e2f3..1fcc8287ed6 100644 --- a/crates/hir-expand/Cargo.toml +++ b/crates/hir-expand/Cargo.toml @@ -19,6 +19,7 @@ itertools = "0.10.3" hashbrown = { version = "0.12.1", features = [ "inline-more", ], default-features = false } +smallvec = { version = "1.9.0", features = ["const_new"] } stdx = { path = "../stdx", version = "0.0.0" } base-db = { path = "../base-db", version = "0.0.0" } diff --git a/crates/hir-expand/src/mod_path.rs b/crates/hir-expand/src/mod_path.rs index af59733b9f1..05e8c585c98 100644 --- a/crates/hir-expand/src/mod_path.rs +++ b/crates/hir-expand/src/mod_path.rs @@ -12,12 +12,13 @@ use crate::{ }; use base_db::CrateId; use either::Either; +use smallvec::SmallVec; use syntax::{ast, AstNode}; #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct ModPath { pub kind: PathKind, - segments: Vec<Name>, + segments: SmallVec<[Name; 1]>, } #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] @@ -41,13 +42,13 @@ impl ModPath { } pub fn from_segments(kind: PathKind, segments: impl IntoIterator<Item = Name>) -> ModPath { - let segments = segments.into_iter().collect::<Vec<_>>(); + let segments = segments.into_iter().collect(); ModPath { kind, segments } } /// Creates a `ModPath` from a `PathKind`, with no extra path segments. pub const fn from_kind(kind: PathKind) -> ModPath { - ModPath { kind, segments: Vec::new() } + ModPath { kind, segments: SmallVec::new_const() } } pub fn segments(&self) -> &[Name] { |
