Skip to content

Commit 67a9fe9

Browse files
refactor: unnecessary vector creation
Signed-off-by: Maika Namuo <httpworldview@gmail.com>
1 parent 571568c commit 67a9fe9

2 files changed

Lines changed: 13 additions & 14 deletions

File tree

‎src/ui/settings/waveform.rs‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,12 @@ const BAND_DB_FLOOR_RANGE: SliderRange =
2020
SliderRange::new(MIN_BAND_DB_FLOOR, MAX_BAND_DB_FLOOR, 1.0);
2121

2222
fn configure_palette_for_mode(palette: &mut PaletteEditor, mode: WaveformColorMode) {
23-
let (visible, labels) = match mode {
24-
WaveformColorMode::Static => (Some(vec![0]), vec![(0, "Color")]),
25-
WaveformColorMode::Loudness => (None, vec![(0, "Quiet"), (1, "->"), (2, "Loud")]),
26-
WaveformColorMode::Frequency => (None, Vec::new()),
27-
};
28-
palette.set_visible_indices(visible);
29-
palette.set_label_overrides(labels);
23+
palette.set_visible_indices((mode == WaveformColorMode::Static).then_some(&[0][..]));
24+
palette.set_label_overrides(match mode {
25+
WaveformColorMode::Static => &[(0, "Color")],
26+
WaveformColorMode::Loudness => &[(0, "Quiet"), (1, "->"), (2, "Loud")],
27+
WaveformColorMode::Frequency => &[],
28+
});
3029
}
3130

3231
settings_messages!(pane, value {

‎src/ui/widgets/palette_editor.rs‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ pub struct PaletteEditor {
4545
positions: Vec<f32>,
4646
spreads: Vec<f32>,
4747
active: Option<usize>,
48-
visible_indices: Option<Vec<usize>>,
49-
label_overrides: Vec<(usize, &'static str)>,
48+
visible_indices: Option<&'static [usize]>,
49+
label_overrides: &'static [(usize, &'static str)],
5050
show_ramp: bool,
5151
scroll: ScrollGlow,
5252
}
@@ -59,7 +59,7 @@ impl PaletteEditor {
5959
palette,
6060
active: None,
6161
visible_indices: None,
62-
label_overrides: Vec::new(),
62+
label_overrides: &[],
6363
show_ramp: false,
6464
scroll: ScrollGlow::default(),
6565
}
@@ -69,16 +69,16 @@ impl PaletteEditor {
6969
self.show_ramp = show;
7070
}
7171

72-
pub fn set_visible_indices(&mut self, indices: Option<Vec<usize>>) {
72+
pub fn set_visible_indices(&mut self, indices: Option<&'static [usize]>) {
7373
self.visible_indices = indices;
74-
if let (Some(active), Some(visible)) = (self.active, &self.visible_indices)
74+
if let Some((active, visible)) = self.active.zip(self.visible_indices)
7575
&& !visible.contains(&active)
7676
{
7777
self.active = None;
7878
}
7979
}
8080

81-
pub fn set_label_overrides(&mut self, overrides: Vec<(usize, &'static str)>) {
81+
pub fn set_label_overrides(&mut self, overrides: &'static [(usize, &'static str)]) {
8282
self.label_overrides = overrides;
8383
}
8484

@@ -200,7 +200,7 @@ impl PaletteEditor {
200200
pub fn view(&self) -> Element<'_, PaletteEvent> {
201201
let colors = self.palette.colors();
202202
let mut row = Row::new().spacing(12.0);
203-
if let Some(indices) = &self.visible_indices {
203+
if let Some(indices) = self.visible_indices {
204204
for &i in indices {
205205
if let Some(&color) = colors.get(i) {
206206
row = row.push(self.color_picker(i, color));

0 commit comments

Comments
 (0)