summaryrefslogtreecommitdiffstats
path: root/wgpu
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2023-05-30 01:14:41 +0200
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2023-05-30 01:14:41 +0200
commitcd7d33aa8ebc6fbb6666f34aeda3ee96d0fb51e3 (patch)
treecfbe00ed855cdf12a76a533b151ead636e4d73fe /wgpu
parent6d650e7f9987aa72913d20c7e538448b518a6150 (diff)
downloadiced-cd7d33aa8ebc6fbb6666f34aeda3ee96d0fb51e3.tar.gz
iced-cd7d33aa8ebc6fbb6666f34aeda3ee96d0fb51e3.tar.bz2
iced-cd7d33aa8ebc6fbb6666f34aeda3ee96d0fb51e3.zip
Simplify `order` match statement in `quad::Batch::add`
Diffstat (limited to 'wgpu')
-rw-r--r--wgpu/src/quad.rs35
1 files changed, 9 insertions, 26 deletions
diff --git a/wgpu/src/quad.rs b/wgpu/src/quad.rs
index 48ef565e..e25d02af 100644
--- a/wgpu/src/quad.rs
+++ b/wgpu/src/quad.rs
@@ -244,9 +244,6 @@ pub struct Batch {
/// The quad order of the [`Layer`]; stored as a tuple of the quad type & its count.
order: Vec<(Kind, usize)>,
-
- /// The last index of quad ordering.
- index: usize,
}
impl Batch {
@@ -257,7 +254,7 @@ impl Batch {
/// Adds a [`Quad`] with the provided `Background` type to the quad [`Layer`].
pub fn add(&mut self, quad: Quad, background: &Background) {
- let quad_order = match background {
+ let kind = match background {
Background::Color(color) => {
self.solids.push(Solid {
color: color.into_linear(),
@@ -276,37 +273,23 @@ impl Batch {
};
self.gradients.push(quad);
+
Kind::Gradient
}
};
- match (self.order.get_mut(self.index), quad_order) {
- (Some((quad_order, count)), Kind::Solid) => match quad_order {
- Kind::Solid => {
- *count += 1;
- }
- Kind::Gradient => {
- self.order.push((Kind::Solid, 1));
- self.index += 1;
- }
- },
- (Some((quad_order, count)), Kind::Gradient) => match quad_order {
- Kind::Solid => {
- self.order.push((Kind::Gradient, 1));
- self.index += 1;
- }
- Kind::Gradient => {
- *count += 1;
- }
- },
- (None, _) => {
- self.order.push((quad_order, 1));
+ match self.order.last_mut() {
+ Some((last_kind, count)) if kind == *last_kind => {
+ *count += 1;
+ }
+ _ => {
+ self.order.push((kind, 1));
}
}
}
}
-#[derive(Debug, Copy, Clone)]
+#[derive(Debug, Copy, Clone, PartialEq, Eq)]
/// The kind of a quad.
enum Kind {
/// A solid quad