Skip to content

Commit 4d38a29

Browse files
committed
avoid more allocations
1 parent a8b87ba commit 4d38a29

File tree

14 files changed

+126
-126
lines changed

14 files changed

+126
-126
lines changed

cosmic-app-list/src/app.rs

Lines changed: 79 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl AppletIconData {
8282
let padding = applet.suggested_padding(false);
8383
let icon_spacing = 4.0;
8484

85-
let (dot_radius, bar_size) = match applet.size {
85+
let (dot_radius, bar_size): (f32, f32) = match applet.size {
8686
Size::Hardcoded(_) => (2.0, 8.0),
8787
Size::PanelSize(ref s) => {
8888
let size = s.get_applet_icon_size_with_padding(false);
@@ -102,10 +102,30 @@ impl AppletIconData {
102102
let padding = padding as f32;
103103

104104
let padding = match applet.anchor {
105-
PanelAnchor::Top => [padding - (dot_radius * 2. + 1.), padding, padding, padding],
106-
PanelAnchor::Bottom => [padding, padding, padding - (dot_radius * 2. + 1.), padding],
107-
PanelAnchor::Left => [padding, padding, padding, padding - (dot_radius * 2. + 1.)],
108-
PanelAnchor::Right => [padding, padding - (dot_radius * 2. + 1.), padding, padding],
105+
PanelAnchor::Top => [
106+
padding - dot_radius.mul_add(2., 1.),
107+
padding,
108+
padding,
109+
padding,
110+
],
111+
PanelAnchor::Bottom => [
112+
padding,
113+
padding,
114+
padding - dot_radius.mul_add(2., 1.),
115+
padding,
116+
],
117+
PanelAnchor::Left => [
118+
padding,
119+
padding,
120+
padding,
121+
padding - dot_radius.mul_add(2., 1.),
122+
],
123+
PanelAnchor::Right => [
124+
padding,
125+
padding - dot_radius.mul_add(2., 1.),
126+
padding,
127+
padding,
128+
],
109129
};
110130
AppletIconData {
111131
icon_size,
@@ -212,32 +232,32 @@ impl DockItem {
212232
};
213233

214234
let icon_wrapper: Element<_> = match applet.anchor {
215-
PanelAnchor::Left => row([
216-
indicator.into(),
217-
horizontal_space().width(Length::Fixed(1.0)).into(),
218-
cosmic_icon.clone().into(),
219-
])
235+
PanelAnchor::Left => row![
236+
indicator,
237+
horizontal_space().width(Length::Fixed(1.0)),
238+
cosmic_icon.clone(),
239+
]
220240
.align_y(Alignment::Center)
221241
.into(),
222-
PanelAnchor::Right => row([
223-
cosmic_icon.clone().into(),
224-
horizontal_space().width(Length::Fixed(1.0)).into(),
225-
indicator.into(),
226-
])
242+
PanelAnchor::Right => row![
243+
cosmic_icon.clone(),
244+
horizontal_space().width(Length::Fixed(1.0)),
245+
indicator,
246+
]
227247
.align_y(Alignment::Center)
228248
.into(),
229-
PanelAnchor::Top => column([
230-
indicator.into(),
231-
vertical_space().height(Length::Fixed(1.0)).into(),
232-
cosmic_icon.clone().into(),
233-
])
249+
PanelAnchor::Top => column![
250+
indicator,
251+
vertical_space().height(Length::Fixed(1.0)),
252+
cosmic_icon.clone(),
253+
]
234254
.align_x(Alignment::Center)
235255
.into(),
236-
PanelAnchor::Bottom => column([
237-
cosmic_icon.clone().into(),
238-
vertical_space().height(Length::Fixed(1.0)).into(),
239-
indicator.into(),
240-
])
256+
PanelAnchor::Bottom => column![
257+
cosmic_icon.clone(),
258+
vertical_space().height(Length::Fixed(1.0)),
259+
indicator,
260+
]
241261
.align_x(Alignment::Center)
242262
.into(),
243263
};
@@ -453,9 +473,7 @@ where
453473
column![
454474
container(if let Some(img) = img {
455475
Element::from(Image::new(Handle::from_rgba(
456-
img.width,
457-
img.height,
458-
img.img.clone(),
476+
img.width, img.height, img.img,
459477
)))
460478
} else {
461479
Image::new(Handle::from_rgba(1, 1, [0u8, 0u8, 0u8, 255u8].as_slice())).into()
@@ -769,24 +787,24 @@ impl cosmic::Application for CosmicAppList {
769787
height: height as i32,
770788
};
771789
let max_windows = 7.0;
772-
let window_spacing = 8.0;
790+
let window_spacing = 8.0_f32;
773791
popup_settings.positioner.size_limits = match self.core.applet.anchor {
774792
PanelAnchor::Right | PanelAnchor::Left => Limits::NONE
775793
.min_width(100.0)
776794
.min_height(30.0)
777-
.max_width(window_spacing * 2.0 + TOPLEVEL_BUTTON_WIDTH)
795+
.max_width(window_spacing.mul_add(2.0, TOPLEVEL_BUTTON_WIDTH))
778796
.max_height(
779-
TOPLEVEL_BUTTON_HEIGHT * max_windows
780-
+ window_spacing * (max_windows + 1.0),
797+
TOPLEVEL_BUTTON_HEIGHT
798+
.mul_add(max_windows, window_spacing * (max_windows + 1.0)),
781799
),
782800
PanelAnchor::Bottom | PanelAnchor::Top => Limits::NONE
783801
.min_width(30.0)
784802
.min_height(100.0)
785803
.max_width(
786-
TOPLEVEL_BUTTON_WIDTH * max_windows
787-
+ window_spacing * (max_windows + 1.0),
804+
TOPLEVEL_BUTTON_WIDTH
805+
.mul_add(max_windows, window_spacing * (max_windows + 1.0)),
788806
)
789-
.max_height(window_spacing * 2.0 + TOPLEVEL_BUTTON_HEIGHT),
807+
.max_height(window_spacing.mul_add(2.0, TOPLEVEL_BUTTON_HEIGHT)),
790808
};
791809

792810
return get_popup(popup_settings);
@@ -883,8 +901,7 @@ impl cosmic::Application for CosmicAppList {
883901
})
884902
{
885903
let icon_id = window::Id::unique();
886-
self.dnd_source =
887-
Some((icon_id, toplevel_group.clone(), DndAction::empty(), pos));
904+
self.dnd_source = Some((icon_id, toplevel_group, DndAction::empty(), pos));
888905
}
889906
}
890907
Message::DragFinished => {
@@ -1141,7 +1158,7 @@ impl cosmic::Application for CosmicAppList {
11411158
updated_appid = true;
11421159
}
11431160

1144-
*t_info = info.clone();
1161+
t_info.clone_from(&info);
11451162
break 'toplevel_loop;
11461163
}
11471164
}
@@ -1298,7 +1315,7 @@ impl cosmic::Application for CosmicAppList {
12981315
DockItem {
12991316
id: self.item_ctr,
13001317
toplevels: Vec::new(),
1301-
desktop_info: de.clone(),
1318+
desktop_info: de,
13021319
original_app_id: original_id.clone(),
13031320
}
13041321
}
@@ -1357,8 +1374,8 @@ impl cosmic::Application for CosmicAppList {
13571374
self.active_list.len().saturating_sub(
13581375
(active_popup_cutoff.unwrap_or_default()).saturating_sub(1),
13591376
) as f32;
1360-
let popup_applet_size = applet_suggested_size as f32 * popup_applet_count
1361-
+ 4.0 * (popup_applet_count - 1.);
1377+
let popup_applet_size = (applet_suggested_size as f32)
1378+
.mul_add(popup_applet_count, 4.0 * (popup_applet_count - 1.));
13621379
let (max_width, max_height) = match self.core.applet.anchor {
13631380
PanelAnchor::Top | PanelAnchor::Bottom => {
13641381
(popup_applet_size, applet_suggested_size.into())
@@ -1414,8 +1431,8 @@ impl cosmic::Application for CosmicAppList {
14141431
self.pinned_list.len().saturating_sub(
14151432
favorite_popup_cutoff.unwrap_or_default().saturating_sub(1),
14161433
) as f32;
1417-
let popup_applet_size = applet_suggested_size as f32 * popup_applet_count
1418-
+ 4.0 * (popup_applet_count - 1.);
1434+
let popup_applet_size = (applet_suggested_size as f32)
1435+
.mul_add(popup_applet_count, 4.0 * (popup_applet_count - 1.));
14191436
let (max_width, max_height) = match self.core.applet.anchor {
14201437
PanelAnchor::Top | PanelAnchor::Bottom => {
14211438
(popup_applet_size, applet_suggested_size as f32)
@@ -1665,11 +1682,11 @@ impl cosmic::Application for CosmicAppList {
16651682
Length::Shrink,
16661683
Length::Shrink,
16671684
DndDestination::for_data::<DndPathBuf>(
1668-
row(favorites).spacing(app_icon.icon_spacing),
1685+
Row::from_vec(favorites).spacing(app_icon.icon_spacing),
16691686
|_, _| Message::DndDropFinished,
16701687
)
16711688
.drag_id(DND_FAVORITES),
1672-
row(active).spacing(app_icon.icon_spacing).into(),
1689+
Row::from_vec(active).spacing(app_icon.icon_spacing).into(),
16731690
container(vertical_rule(1))
16741691
.height(Length::Fill)
16751692
.padding([divider_padding, 0])
@@ -1680,11 +1697,13 @@ impl cosmic::Application for CosmicAppList {
16801697
Length::Shrink,
16811698
Length::Shrink,
16821699
DndDestination::for_data(
1683-
column(favorites).spacing(app_icon.icon_spacing),
1700+
Column::from_vec(favorites).spacing(app_icon.icon_spacing),
16841701
|_data: Option<DndPathBuf>, _| Message::DndDropFinished,
16851702
)
16861703
.drag_id(DND_FAVORITES),
1687-
column(active).spacing(app_icon.icon_spacing).into(),
1704+
Column::from_vec(active)
1705+
.spacing(app_icon.icon_spacing)
1706+
.into(),
16881707
container(divider::horizontal::default())
16891708
.width(Length::Fill)
16901709
.padding([0, divider_padding])
@@ -1847,7 +1866,7 @@ impl cosmic::Application for CosmicAppList {
18471866
}
18481867

18491868
if !toplevels.is_empty() {
1850-
let mut list_col = column![];
1869+
let mut list_col = Column::with_capacity(toplevels.len());
18511870
for (info, _) in toplevels {
18521871
let title = if info.title.len() > 34 {
18531872
format!("{:.32}...", &info.title)
@@ -1937,8 +1956,10 @@ impl cosmic::Application for CosmicAppList {
19371956
}
19381957
PopupType::TopLevelList => match self.core.applet.anchor {
19391958
PanelAnchor::Left | PanelAnchor::Right => {
1940-
let mut content =
1941-
column![].padding(8).align_x(Alignment::Center).spacing(8);
1959+
let mut content = Column::with_capacity(toplevels.len())
1960+
.padding(8)
1961+
.align_x(Alignment::Center)
1962+
.spacing(8);
19421963
for (info, img) in toplevels {
19431964
let title = if info.title.len() > 18 {
19441965
format!("{:.16}...", &info.title)
@@ -1960,7 +1981,10 @@ impl cosmic::Application for CosmicAppList {
19601981
.into()
19611982
}
19621983
PanelAnchor::Bottom | PanelAnchor::Top => {
1963-
let mut content = row![].padding(8).align_y(Alignment::Center).spacing(8);
1984+
let mut content = Row::with_capacity(toplevels.len())
1985+
.padding(8)
1986+
.align_y(Alignment::Center)
1987+
.spacing(8);
19641988
for (info, img) in toplevels {
19651989
let title = if info.title.len() > 18 {
19661990
format!("{:.16}...", &info.title)
@@ -2171,9 +2195,9 @@ impl cosmic::Application for CosmicAppList {
21712195
.into()
21722196
} else {
21732197
let suggested = self.core.applet.suggested_size(false);
2174-
iced::widget::row!()
2175-
.width(Length::Fixed(suggested.0 as f32))
2176-
.height(Length::Fixed(suggested.1 as f32))
2198+
Row::new()
2199+
.width(Length::Fixed(suggested.0.into()))
2200+
.height(Length::Fixed(suggested.1.into()))
21772201
.into()
21782202
}
21792203
}
@@ -2353,7 +2377,7 @@ impl CosmicAppList {
23532377
continue;
23542378
}
23552379

2356-
fallback_entry = entry.clone();
2380+
fallback_entry.clone_from(entry);
23572381
break;
23582382
}
23592383
}

cosmic-app-list/src/wayland_handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ pub(crate) fn wayland_handler(
620620
.insert_source(rx, |event, (), state| match event {
621621
calloop::channel::Event::Msg(req) => match req {
622622
WaylandRequest::Screencopy(handle) => {
623-
state.send_image(handle.clone());
623+
state.send_image(handle);
624624
}
625625
WaylandRequest::Toplevel(req) => match req {
626626
ToplevelRequest::Activate(handle) => {

cosmic-applet-audio/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ mod pulse;
4242
static FULL_VOLUME: f64 = Volume::NORMAL.0 as f64;
4343

4444
// Max volume is 150% volume.
45-
static MAX_VOLUME: f64 = FULL_VOLUME + (FULL_VOLUME * 0.5);
45+
static MAX_VOLUME: f64 = FULL_VOLUME * 1.5;
4646

4747
static SHOW_MEDIA_CONTROLS: LazyLock<id::Toggler> = LazyLock::new(id::Toggler::unique);
4848

cosmic-applet-audio/src/mpris_subscription.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,12 @@ impl PlayerStatus {
4040

4141
let title = metadata
4242
.title()
43-
.or(pathbuf
44-
.file_name()
45-
.and_then(|s| s.to_str())
46-
.and_then(|s| decode(s).map_or(None, |s| Some(s.into_owned()))))
43+
.or_else(|| {
44+
pathbuf
45+
.file_name()
46+
.and_then(|s| s.to_str())
47+
.and_then(|s| decode(s).map_or(None, |s| Some(s.into_owned())))
48+
})
4749
.map(Cow::from);
4850
let artists = metadata
4951
.artists()

cosmic-applet-battery/src/app.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ fn format_duration(duration: Duration) -> String {
5353
if min > 60 {
5454
format!("{}:{:02}", min / 60, min % 60)
5555
} else {
56-
format!("{}{}", min, fl!("minutes"))
56+
format!("{min}{}", fl!("minutes"))
5757
}
5858
} else {
59-
format!("{}{}", secs, fl!("seconds"))
59+
format!("{secs}{}", fl!("seconds"))
6060
}
6161
}
6262

cosmic-applet-battery/src/dgpu.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ async fn powered_on(path: impl AsRef<Path>) -> bool {
9797
"D3cold" | "D3hot" => false,
9898
x => {
9999
debug!(
100-
"Unknown power state {} for node {}",
101-
x,
100+
"Unknown power state {x} for node {}",
102101
path.as_ref().display()
103102
);
104103
true
@@ -231,7 +230,7 @@ impl Gpu {
231230
return None;
232231
}
233232
Err(err) => {
234-
debug!("smi returned error code: {}", err);
233+
debug!("smi returned error code: {err}");
235234
return None;
236235
}
237236
};

cosmic-applet-bluetooth/src/bluetooth.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ pub async fn tick(interval: &mut tokio::time::Interval) {
5353
let guard = TICK.read().await;
5454
if *guard != interval.period() {
5555
*interval = tokio::time::interval(*guard);
56+
drop(guard);
5657
interval.set_missed_tick_behavior(tokio::time::MissedTickBehavior::Skip);
5758
}
5859
interval.tick().await;

0 commit comments

Comments
 (0)