Skip to content

Commit a49c228

Browse files
committed
fix: move instead of clone
1 parent f48f4f5 commit a49c228

File tree

8 files changed

+20
-18
lines changed

8 files changed

+20
-18
lines changed

libs/@local/hashql/core/src/heap/convert.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use core::alloc::Allocator;
44

5-
use super::CloneIn as _;
5+
use super::CollectIn as _;
66

77
/// Construct a value of type `Self` from `T` using the provided allocator.
88
///
@@ -48,10 +48,10 @@ impl<T, A: Allocator> FromIn<T, A> for Box<T, A> {
4848
impl<A: Allocator> FromIn<String, A> for Box<str, A> {
4949
fn from_in(value: String, allocator: A) -> Self {
5050
// This is the same `as_boxed_str`, but with custom allocator support.
51-
let bytes = value.into_bytes().clone_in(allocator).into_boxed_slice();
51+
let bytes: Vec<u8, A> = value.into_bytes().into_iter().collect_in(allocator);
5252

5353
// This is the same as `from_boxed_utf8_unchecked` but with a custom allocator.
54-
let (ptr, alloc) = Box::into_raw_with_allocator(bytes);
54+
let (ptr, alloc) = Box::into_raw_with_allocator(bytes.into_boxed_slice());
5555

5656
// SAFETY: The bytes are guaranteed to be valid UTF-8 because they come from a String.
5757
unsafe { Self::from_raw_in(ptr as *mut str, alloc) }

libs/@local/hashql/core/src/heap/iter.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pub trait FromIteratorIn<T, A: Allocator> {
1313
}
1414

1515
impl<T, A: Allocator> FromIteratorIn<T, A> for Vec<T, A> {
16+
#[inline]
1617
fn from_iter_in<I>(iter: I, alloc: A) -> Self
1718
where
1819
I: IntoIterator<Item = T>,
@@ -36,6 +37,7 @@ impl<I, C: FromIteratorIn<T, A>, T, A: Allocator> CollectIn<C, A> for I
3637
where
3738
I: IntoIterator<Item = T>,
3839
{
40+
#[inline]
3941
fn collect_in(self, alloc: A) -> C {
4042
C::from_iter_in(self, alloc)
4143
}

libs/@local/hashql/syntax-jexpr/src/parser/array/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use hashql_ast::node::{
99
id::NodeId,
1010
path::{Path, PathSegment},
1111
};
12-
use hashql_core::heap::CloneIn as _;
12+
use hashql_core::heap::CollectIn as _;
1313

1414
use self::{
1515
error::{
@@ -236,8 +236,8 @@ pub(crate) fn parse_array<'heap, 'source>(
236236
id: NodeId::PLACEHOLDER,
237237
span,
238238
function: Box::new_in(function, heap),
239-
arguments: arguments.clone_in(heap),
240-
labeled_arguments: labeled_arguments.clone_in(heap),
239+
arguments: arguments.into_iter().collect_in(heap),
240+
labeled_arguments: labeled_arguments.into_iter().collect_in(heap),
241241
}),
242242
})
243243
}

libs/@local/hashql/syntax-jexpr/src/parser/object/dict.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use hashql_ast::node::{
33
id::NodeId,
44
};
55
use hashql_core::{
6-
heap::CloneIn as _,
6+
heap::CollectIn as _,
77
value::{self, Primitive},
88
};
99
use text_size::TextRange;
@@ -117,7 +117,7 @@ fn parse_dict_object<'heap, 'source>(
117117
Ok(DictExpr {
118118
id: NodeId::PLACEHOLDER,
119119
span: state.insert_range(span),
120-
entries: entries.clone_in(state.heap()),
120+
entries: entries.into_iter().collect_in(state.heap()),
121121
r#type: None,
122122
})
123123
}
@@ -191,7 +191,7 @@ fn parse_dict_array<'heap, 'source>(
191191
Ok(DictExpr {
192192
id: NodeId::PLACEHOLDER,
193193
span: state.insert_range(span),
194-
entries: entries.clone_in(state.heap()),
194+
entries: entries.into_iter().collect_in(state.heap()),
195195
r#type: None,
196196
})
197197
}

libs/@local/hashql/syntax-jexpr/src/parser/object/list.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use hashql_ast::node::{
22
expr::{Expr, ExprKind, ListExpr, list::ListElement},
33
id::NodeId,
44
};
5-
use hashql_core::heap::CloneIn as _;
5+
use hashql_core::heap::CollectIn as _;
66
use text_size::TextRange;
77

88
use super::{
@@ -107,7 +107,7 @@ fn parse_list<'heap>(
107107
Ok(ListExpr {
108108
id: NodeId::PLACEHOLDER,
109109
span: state.insert_range(range),
110-
elements: elements.clone_in(state.heap()),
110+
elements: elements.into_iter().collect_in(state.heap()),
111111
r#type: None,
112112
})
113113
}

libs/@local/hashql/syntax-jexpr/src/parser/object/struct.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use hashql_ast::node::{
22
expr::{Expr, ExprKind, StructExpr, r#struct::StructEntry},
33
id::NodeId,
44
};
5-
use hashql_core::heap::CloneIn as _;
5+
use hashql_core::heap::CollectIn as _;
66
use text_size::TextRange;
77

88
use super::{
@@ -124,7 +124,7 @@ fn parse_struct<'heap>(
124124
Ok(StructExpr {
125125
id: NodeId::PLACEHOLDER,
126126
span: state.insert_range(span),
127-
entries: entries.clone_in(state.heap()),
127+
entries: entries.into_iter().collect_in(state.heap()),
128128
r#type: None,
129129
})
130130
}

libs/@local/hashql/syntax-jexpr/src/parser/object/tuple.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use hashql_ast::node::{
22
expr::{Expr, ExprKind, TupleExpr, tuple::TupleElement},
33
id::NodeId,
44
};
5-
use hashql_core::heap::CloneIn as _;
5+
use hashql_core::heap::CollectIn as _;
66
use text_size::TextRange;
77

88
use super::{
@@ -107,7 +107,7 @@ fn parse_tuple<'heap>(
107107
Ok(TupleExpr {
108108
id: NodeId::PLACEHOLDER,
109109
span: state.insert_range(range),
110-
elements: elements.clone_in(state.heap()),
110+
elements: elements.into_iter().collect_in(state.heap()),
111111
r#type: None,
112112
})
113113
}

libs/@local/hashql/syntax-jexpr/src/parser/string/type.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use hashql_ast::node::{
66
IntersectionType, StructField, StructType, TupleField, TupleType, Type, TypeKind, UnionType,
77
},
88
};
9-
use hashql_core::{heap::CloneIn as _, symbol::Ident};
9+
use hashql_core::{heap::CollectIn as _, symbol::Ident};
1010
use winnow::{
1111
ModalParser, ModalResult, Parser as _,
1212
ascii::multispace0,
@@ -184,7 +184,7 @@ where
184184
kind: TypeKind::Struct(StructType {
185185
id: NodeId::PLACEHOLDER,
186186
span,
187-
fields: fields.clone_in(input.state.heap),
187+
fields: fields.into_iter().collect_in(input.state.heap),
188188
}),
189189
})
190190
}
@@ -237,7 +237,7 @@ where
237237
kind: TypeKind::Tuple(TupleType {
238238
id: NodeId::PLACEHOLDER,
239239
span,
240-
fields: fields.clone_in(input.state.heap),
240+
fields: fields.into_iter().collect_in(input.state.heap),
241241
}),
242242
})
243243
}

0 commit comments

Comments
 (0)