Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Use explicit sort order instead of comparison impls for gpui prims (#21430)
Michael Sloanf4dbcb67143a
diff --git a/crates/gpui/src/scene.rs b/crates/gpui/src/scene.rsindex 9787ec5d87f..418be6af22b 100644--- a/crates/gpui/src/scene.rs+++ b/crates/gpui/src/scene.rs@@ -128,13 +128,15 @@ impl Scene {}pub fn finish(&mut self) {- self.shadows.sort();- self.quads.sort();- self.paths.sort();- self.underlines.sort();- self.monochrome_sprites.sort();- self.polychrome_sprites.sort();- self.surfaces.sort();+ self.shadows.sort_by_key(|shadow| shadow.order);+ self.quads.sort_by_key(|quad| quad.order);+ self.paths.sort_by_key(|path| path.order);+ self.underlines.sort_by_key(|underline| underline.order);+ self.monochrome_sprites+ .sort_by_key(|sprite| (sprite.order, sprite.tile.tile_id));+ self.polychrome_sprites+ .sort_by_key(|sprite| (sprite.order, sprite.tile.tile_id));+ self.surfaces.sort_by_key(|surface| surface.order);}#[cfg_attr(@@ -196,7 +198,7 @@ pub(crate) enum PaintOperation {EndLayer,}-#[derive(Clone, Ord, PartialOrd, Eq, PartialEq)]+#[derive(Clone)]pub(crate) enum Primitive {Shadow(Shadow),Quad(Quad),@@ -449,7 +451,7 @@ pub(crate) enum PrimitiveBatch<'a> {Surfaces(&'a [PaintSurface]),}-#[derive(Default, Debug, Clone, Eq, PartialEq)]+#[derive(Default, Debug, Clone)]#[repr(C)]pub(crate) struct Quad {pub order: DrawOrder,@@ -462,25 +464,13 @@ pub(crate) struct Quad {pub border_widths: Edges<ScaledPixels>,}-impl Ord for Quad {- fn cmp(&self, other: &Self) -> std::cmp::Ordering {- self.order.cmp(&other.order)- }-}--impl PartialOrd for Quad {- fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {- Some(self.cmp(other))- }-}-impl From<Quad> for Primitive {fn from(quad: Quad) -> Self {Primitive::Quad(quad)}}-#[derive(Debug, Clone, Eq, PartialEq)]+#[derive(Debug, Clone)]#[repr(C)]pub(crate) struct Underline {pub order: DrawOrder,@@ -492,25 +482,13 @@ pub(crate) struct Underline {pub wavy: bool,}-impl Ord for Underline {- fn cmp(&self, other: &Self) -> std::cmp::Ordering {- self.order.cmp(&other.order)- }-}--impl PartialOrd for Underline {- fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {- Some(self.cmp(other))- }-}-impl From<Underline> for Primitive {fn from(underline: Underline) -> Self {Primitive::Underline(underline)}}-#[derive(Debug, Clone, Eq, PartialEq)]+#[derive(Debug, Clone)]#[repr(C)]pub(crate) struct Shadow {pub order: DrawOrder,@@ -521,18 +499,6 @@ pub(crate) struct Shadow {pub color: Hsla,}-impl Ord for Shadow {- fn cmp(&self, other: &Self) -> std::cmp::Ordering {- self.order.cmp(&other.order)- }-}--impl PartialOrd for Shadow {- fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {- Some(self.cmp(other))- }-}-impl From<Shadow> for Primitive {fn from(shadow: Shadow) -> Self {Primitive::Shadow(shadow)@@ -642,7 +608,7 @@ impl Default for TransformationMatrix {}}-#[derive(Clone, Debug, Eq, PartialEq)]+#[derive(Clone, Debug)]#[repr(C)]pub(crate) struct MonochromeSprite {pub order: DrawOrder,@@ -654,28 +620,13 @@ pub(crate) struct MonochromeSprite {pub transformation: TransformationMatrix,}-impl Ord for MonochromeSprite {- fn cmp(&self, other: &Self) -> std::cmp::Ordering {- match self.order.cmp(&other.order) {- std::cmp::Ordering::Equal => self.tile.tile_id.cmp(&other.tile.tile_id),- order => order,- }- }-}--impl PartialOrd for MonochromeSprite {- fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {- Some(self.cmp(other))- }-}-impl From<MonochromeSprite> for Primitive {fn from(sprite: MonochromeSprite) -> Self {Primitive::MonochromeSprite(sprite)}}-#[derive(Clone, Debug, PartialEq)]+#[derive(Clone, Debug)]#[repr(C)]pub(crate) struct PolychromeSprite {pub order: DrawOrder,@@ -687,22 +638,6 @@ pub(crate) struct PolychromeSprite {pub corner_radii: Corners<ScaledPixels>,pub tile: AtlasTile,}-impl Eq for PolychromeSprite {}--impl Ord for PolychromeSprite {- fn cmp(&self, other: &Self) -> std::cmp::Ordering {- match self.order.cmp(&other.order) {- std::cmp::Ordering::Equal => self.tile.tile_id.cmp(&other.tile.tile_id),- order => order,- }- }-}--impl PartialOrd for PolychromeSprite {- fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {- Some(self.cmp(other))- }-}impl From<PolychromeSprite> for Primitive {fn from(sprite: PolychromeSprite) -> Self {@@ -710,7 +645,7 @@ impl From<PolychromeSprite> for Primitive {}}-#[derive(Clone, Debug, Eq, PartialEq)]+#[derive(Clone, Debug)]pub(crate) struct PaintSurface {pub order: DrawOrder,pub bounds: Bounds<ScaledPixels>,@@ -719,18 +654,6 @@ pub(crate) struct PaintSurface {pub image_buffer: media::core_video::CVImageBuffer,}-impl Ord for PaintSurface {- fn cmp(&self, other: &Self) -> std::cmp::Ordering {- self.order.cmp(&other.order)- }-}--impl PartialOrd for PaintSurface {- fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {- Some(self.cmp(other))- }-}-impl From<PaintSurface> for Primitive {fn from(surface: PaintSurface) -> Self {Primitive::Surface(surface)@@ -859,26 +782,6 @@ impl Path<Pixels> {}}-impl Eq for Path<ScaledPixels> {}--impl PartialEq for Path<ScaledPixels> {- fn eq(&self, other: &Self) -> bool {- self.order == other.order- }-}--impl Ord for Path<ScaledPixels> {- fn cmp(&self, other: &Self) -> std::cmp::Ordering {- self.order.cmp(&other.order)- }-}--impl PartialOrd for Path<ScaledPixels> {- fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {- Some(self.cmp(other))- }-}-impl From<Path<ScaledPixels>> for Primitive {fn from(path: Path<ScaledPixels>) -> Self {Primitive::Path(path)