Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
gpui: Reduce manual shifting & other minor improvements (#34407)
tidelyd1abba0d336b
diff --git a/crates/docs_preprocessor/src/main.rs b/crates/docs_preprocessor/src/main.rsindex c8e945c7e83..8eeeb6f0c5a 100644--- a/crates/docs_preprocessor/src/main.rs+++ b/crates/docs_preprocessor/src/main.rs@@ -243,7 +243,6 @@ struct ActionDef {fn dump_all_gpui_actions() -> Vec<ActionDef> {let mut actions = gpui::generate_list_of_all_registered_actions()- .into_iter().map(|action| ActionDef {name: action.name,human_name: command_palette::humanize_action_name(action.name),diff --git a/crates/gpui/src/action.rs b/crates/gpui/src/action.rsindex e099bfec28c..b179076cd5f 100644--- a/crates/gpui/src/action.rs+++ b/crates/gpui/src/action.rs@@ -403,12 +403,10 @@ impl ActionRegistry {/// Useful for transforming the list of available actions into a/// format suited for static analysis such as in validating keymaps, or/// generating documentation.-pub fn generate_list_of_all_registered_actions() -> Vec<MacroActionData> {- let mut actions = Vec::new();- for builder in inventory::iter::<MacroActionBuilder> {- actions.push(builder.0());- }- actions+pub fn generate_list_of_all_registered_actions() -> impl Iterator<Item = MacroActionData> {+ inventory::iter::<MacroActionBuilder>+ .into_iter()+ .map(|builder| builder.0())}mod no_action {diff --git a/crates/gpui/src/app.rs b/crates/gpui/src/app.rsindex 6cecfcc0e42..957c7c4be6e 100644--- a/crates/gpui/src/app.rs+++ b/crates/gpui/src/app.rs@@ -1250,11 +1250,7 @@ impl App {.downcast::<T>().unwrap().update(cx, |entity_state, cx| {- if let Some(window) = window {- on_new(entity_state, Some(window), cx);- } else {- on_new(entity_state, None, cx);- }+ on_new(entity_state, window.as_deref_mut(), cx)})},),diff --git a/crates/gpui/src/color.rs b/crates/gpui/src/color.rsindex 7fc9c243939..a16c8f46bef 100644--- a/crates/gpui/src/color.rs+++ b/crates/gpui/src/color.rs@@ -12,18 +12,13 @@ use std::{/// Convert an RGB hex color code number to a color typepub fn rgb(hex: u32) -> Rgba {- let r = ((hex >> 16) & 0xFF) as f32 / 255.0;- let g = ((hex >> 8) & 0xFF) as f32 / 255.0;- let b = (hex & 0xFF) as f32 / 255.0;+ let [_, r, g, b] = hex.to_be_bytes().map(|b| (b as f32) / 255.0);Rgba { r, g, b, a: 1.0 }}/// Convert an RGBA hex color code number to [`Rgba`]pub fn rgba(hex: u32) -> Rgba {- let r = ((hex >> 24) & 0xFF) as f32 / 255.0;- let g = ((hex >> 16) & 0xFF) as f32 / 255.0;- let b = ((hex >> 8) & 0xFF) as f32 / 255.0;- let a = (hex & 0xFF) as f32 / 255.0;+ let [r, g, b, a] = hex.to_be_bytes().map(|b| (b as f32) / 255.0);Rgba { r, g, b, a }}@@ -63,14 +58,14 @@ impl Rgba {if other.a >= 1.0 {other} else if other.a <= 0.0 {- return *self;+ *self} else {- return Rgba {+ Rgba {r: (self.r * (1.0 - other.a)) + (other.r * other.a),g: (self.g * (1.0 - other.a)) + (other.g * other.a),b: (self.b * (1.0 - other.a)) + (other.b * other.a),a: self.a,- };+ }}}}@@ -494,12 +489,12 @@ impl Hsla {if alpha >= 1.0 {other} else if alpha <= 0.0 {- return self;+ self} else {let converted_self = Rgba::from(self);let converted_other = Rgba::from(other);let blended_rgb = converted_self.blend(converted_other);- return Hsla::from(blended_rgb);+ Hsla::from(blended_rgb)}}diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rsindex 59f432faafb..6309c3a1373 100644--- a/crates/zed/src/main.rs+++ b/crates/zed/src/main.rs@@ -1391,7 +1391,6 @@ fn dump_all_gpui_actions() {documentation: Option<&'static str>,}let mut actions = gpui::generate_list_of_all_registered_actions()- .into_iter().map(|action| ActionDef {name: action.name,human_name: command_palette::humanize_action_name(action.name),