Skip to content

Commit 890da6a

Browse files
Firestar99Keavon
andauthored
Clean up code by using Iterator::collect() when constructing instance tables (#2918)
* instances: `Iterator::collect()` instances * instances: adjust nodes to use iterators * fix warnings on master * Bump MSRV * Port the remaining usages --------- Co-authored-by: Keavon Chambers <keavon@keavon.com>
1 parent 032f9bd commit 890da6a

File tree

18 files changed

+980
-1001
lines changed

18 files changed

+980
-1001
lines changed

editor/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "graphite-editor"
33
publish = false
44
version = "0.0.0"
5-
rust-version = "1.85"
5+
rust-version = "1.88"
66
authors = ["Graphite Authors <contact@graphite.rs>"]
77
edition = "2024"
88
readme = "../README.md"

editor/src/messages/portfolio/document/utility_types/network_interface.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6804,13 +6804,6 @@ impl From<DocumentNodePersistentMetadataPropertiesRow> for DocumentNodePersisten
68046804
}
68056805
}
68066806

6807-
#[derive(serde::Serialize, serde::Deserialize)]
6808-
enum NodePersistentMetadataVersions {
6809-
DocumentNodePersistentMetadataPropertiesRow(DocumentNodePersistentMetadataPropertiesRow),
6810-
NodePersistentMetadataInputNames(DocumentNodePersistentMetadataInputNames),
6811-
NodePersistentMetadata(DocumentNodePersistentMetadata),
6812-
}
6813-
68146807
fn deserialize_node_persistent_metadata<'de, D>(deserializer: D) -> Result<DocumentNodePersistentMetadata, D::Error>
68156808
where
68166809
D: serde::Deserializer<'de>,

editor/src/messages/tool/common_functionality/shape_editor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,7 @@ impl ShapeState {
10001000
} else {
10011001
// Push both in and out handles into the correct position
10021002
for ((handle, sign), other_anchor) in handles.iter().zip([1., -1.]).zip(&anchor_positions) {
1003-
let Some(anchor_vector) = other_anchor.map(|position| (position - anchor_position)) else {
1003+
let Some(anchor_vector) = other_anchor.map(|position| position - anchor_position) else {
10041004
continue;
10051005
};
10061006

frontend/wasm/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "graphite-wasm"
33
publish = false
44
version = "0.0.0"
5-
rust-version = "1.85"
5+
rust-version = "1.88"
66
authors = ["Graphite Authors <contact@graphite.rs>"]
77
edition = "2024"
88
readme = "../../README.md"
@@ -13,7 +13,7 @@ license = "Apache-2.0"
1313
[features]
1414
default = ["gpu"]
1515
gpu = ["editor/gpu"]
16-
tauri = [ "editor/tauri"]
16+
tauri = ["editor/tauri"]
1717

1818
[lib]
1919
crate-type = ["cdylib", "rlib"]

libraries/bezier-rs/src/poisson_disk.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ where
169169
A::Item: Clone,
170170
B::Item: Clone,
171171
{
172-
a.flat_map(move |i| (b.clone().map(move |j| (i.clone(), j))))
172+
a.flat_map(move |i| b.clone().map(move |j| (i.clone(), j)))
173173
}
174174

175175
/// A square (represented by its top left corner position and width/height of `square_size`) that is currently a candidate for targetting by the dart throwing process.

libraries/path-bool/src/path_boolean.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,7 @@ fn compute_dual(minor_graph: &MinorGraph) -> Result<DualGraph, BooleanError> {
10861086
let outer_face_key = if count != 1 {
10871087
#[cfg(feature = "logging")]
10881088
eprintln!("Found multiple outer faces: {areas:?}, falling back to area calculation");
1089-
let (key, _) = *areas.iter().max_by_key(|(_, area)| ((area.abs() * 1000.) as u64)).unwrap();
1089+
let (key, _) = *areas.iter().max_by_key(|(_, area)| (area.abs() * 1000.) as u64).unwrap();
10901090
*key
10911091
} else {
10921092
*windings

node-graph/gcore/src/instances.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,24 @@ impl<T> Instances<T> {
2727
}
2828
}
2929

30+
pub fn new_instance(instance: Instance<T>) -> Self {
31+
Self {
32+
instance: vec![instance.instance],
33+
transform: vec![instance.transform],
34+
alpha_blending: vec![instance.alpha_blending],
35+
source_node_id: vec![instance.source_node_id],
36+
}
37+
}
38+
39+
pub fn with_capacity(capacity: usize) -> Self {
40+
Self {
41+
instance: Vec::with_capacity(capacity),
42+
transform: Vec::with_capacity(capacity),
43+
alpha_blending: Vec::with_capacity(capacity),
44+
source_node_id: Vec::with_capacity(capacity),
45+
}
46+
}
47+
3048
pub fn push(&mut self, instance: Instance<T>) {
3149
self.instance.push(instance.instance);
3250
self.transform.push(instance.transform);
@@ -161,6 +179,18 @@ unsafe impl<T: StaticType + 'static> StaticType for Instances<T> {
161179
type Static = Instances<T>;
162180
}
163181

182+
impl<T> FromIterator<Instance<T>> for Instances<T> {
183+
fn from_iter<I: IntoIterator<Item = Instance<T>>>(iter: I) -> Self {
184+
let iter = iter.into_iter();
185+
let (lower, _) = iter.size_hint();
186+
let mut instances = Self::with_capacity(lower);
187+
for instance in iter {
188+
instances.push(instance);
189+
}
190+
instances
191+
}
192+
}
193+
164194
fn one_daffine2_default() -> Vec<DAffine2> {
165195
vec![DAffine2::IDENTITY]
166196
}

node-graph/gcore/src/vector/algorithms/poisson_disk.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ where
182182
A::Item: Clone,
183183
B::Item: Clone,
184184
{
185-
a.flat_map(move |i| (b.clone().map(move |j| (i.clone(), j))))
185+
a.flat_map(move |i| b.clone().map(move |j| (i.clone(), j)))
186186
}
187187

188188
/// A square (represented by its top left corner position and width/height of `square_size`) that is currently a candidate for targetting by the dart throwing process.

node-graph/gcore/src/vector/vector_data.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ impl VectorData {
337337
/// Returns the number of linear segments connected to the given point.
338338
pub fn connected_linear_segments(&self, point_id: PointId) -> usize {
339339
self.segment_bezier_iter()
340-
.filter(|(_, bez, start, end)| ((*start == point_id || *end == point_id) && matches!(bez.handles, BezierHandles::Linear)))
340+
.filter(|(_, bez, start, end)| (*start == point_id || *end == point_id) && matches!(bez.handles, BezierHandles::Linear))
341341
.count()
342342
}
343343

0 commit comments

Comments
 (0)