Skip to content

Commit 91def93

Browse files
committed
Replace Vec with Box in Path.generic_args field
1 parent ceaec9d commit 91def93

File tree

3 files changed

+15
-20
lines changed

3 files changed

+15
-20
lines changed

crates/hir_def/src/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub type LabelId = Idx<Label>;
4040

4141
#[derive(Debug, Clone, Eq, PartialEq)]
4242
pub enum Literal {
43-
String(String),
43+
String(Box<str>),
4444
ByteString(Box<[u8]>),
4545
Char(char),
4646
Bool(bool),

crates/hir_def/src/path.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub struct ModPath {
2222
segments: Vec<Name>,
2323
}
2424

25-
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
25+
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
2626
pub enum PathKind {
2727
Plain,
2828
/// `self::` is `Super(0)`
@@ -119,7 +119,7 @@ pub struct Path {
119119
type_anchor: Option<Interned<TypeRef>>,
120120
mod_path: Interned<ModPath>,
121121
/// Invariant: the same len as `self.mod_path.segments`
122-
generic_args: Vec<Option<Interned<GenericArgs>>>,
122+
generic_args: Box<[Option<Interned<GenericArgs>>]>,
123123
}
124124

125125
/// Generic arguments to a path segment (e.g. the `i32` in `Option<i32>`). This
@@ -171,9 +171,9 @@ impl Path {
171171
/// Converts a known mod path to `Path`.
172172
pub fn from_known_path(
173173
path: ModPath,
174-
generic_args: Vec<Option<Interned<GenericArgs>>>,
174+
generic_args: impl Into<Box<[Option<Interned<GenericArgs>>]>>,
175175
) -> Path {
176-
Path { type_anchor: None, mod_path: Interned::new(path), generic_args }
176+
Path { type_anchor: None, mod_path: Interned::new(path), generic_args: generic_args.into() }
177177
}
178178

179179
pub fn kind(&self) -> &PathKind {
@@ -187,7 +187,7 @@ impl Path {
187187
pub fn segments(&self) -> PathSegments<'_> {
188188
PathSegments {
189189
segments: self.mod_path.segments.as_slice(),
190-
generic_args: self.generic_args.as_slice(),
190+
generic_args: &self.generic_args,
191191
}
192192
}
193193

@@ -205,14 +205,14 @@ impl Path {
205205
self.mod_path.kind.clone(),
206206
self.mod_path.segments[..self.mod_path.segments.len() - 1].iter().cloned(),
207207
)),
208-
generic_args: self.generic_args[..self.generic_args.len() - 1].to_vec(),
208+
generic_args: self.generic_args[..self.generic_args.len() - 1].to_vec().into(),
209209
};
210210
Some(res)
211211
}
212212

213213
pub fn is_self_type(&self) -> bool {
214214
self.type_anchor.is_none()
215-
&& self.generic_args == [None]
215+
&& *self.generic_args == [None]
216216
&& self.mod_path.as_ident() == Some(&name!(Self))
217217
}
218218
}
@@ -286,7 +286,7 @@ impl From<Name> for Path {
286286
Path {
287287
type_anchor: None,
288288
mod_path: Interned::new(ModPath::from_segments(PathKind::Plain, iter::once(name))),
289-
generic_args: vec![None],
289+
generic_args: Box::new([None]),
290290
}
291291
}
292292
}

crates/hir_def/src/path/lower.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,13 @@ pub(super) fn lower_path(mut path: ast::Path, ctx: &LowerCtx) -> Option<Path> {
7070
}
7171
// <T as Trait<A>>::Foo desugars to Trait<Self=T, A>::Foo
7272
Some(trait_ref) => {
73-
let path = Path::from_src(trait_ref.path()?, ctx)?;
74-
let mod_path = (*path.mod_path).clone();
75-
let num_segments = path.mod_path.segments.len();
73+
let Path { mod_path, generic_args: path_generic_args, .. } =
74+
Path::from_src(trait_ref.path()?, ctx)?;
75+
let num_segments = mod_path.segments.len();
7676
kind = mod_path.kind;
7777

78-
let mut prefix_segments = mod_path.segments;
79-
prefix_segments.reverse();
80-
segments.extend(prefix_segments);
81-
82-
let mut prefix_args = path.generic_args;
83-
prefix_args.reverse();
84-
generic_args.extend(prefix_args);
78+
segments.extend(mod_path.segments.iter().cloned().rev());
79+
generic_args.extend(path_generic_args.iter().cloned().rev());
8580

8681
// Insert the type reference (T in the above example) as Self parameter for the trait
8782
let last_segment =
@@ -139,7 +134,7 @@ pub(super) fn lower_path(mut path: ast::Path, ctx: &LowerCtx) -> Option<Path> {
139134
}
140135

141136
let mod_path = Interned::new(ModPath::from_segments(kind, segments));
142-
return Some(Path { type_anchor, mod_path, generic_args });
137+
return Some(Path { type_anchor, mod_path, generic_args: generic_args.into() });
143138

144139
fn qualifier(path: &ast::Path) -> Option<ast::Path> {
145140
if let Some(q) = path.qualifier() {

0 commit comments

Comments
 (0)