Skip to content

Commit a4da53b

Browse files
committed
parser: remove an allocation, fix new clippy warnings
1 parent 40c060c commit a4da53b

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/backend/muxml/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ impl MuxmlGenerator {
231231

232232
let data_range = &self.parsed.measures[measure_idx].data_range;
233233
let ticks_in_measure = rlen(data_range) / 6;
234-
debug_assert!(rlen(data_range) % 6 == 0);
234+
debug_assert!(rlen(data_range).is_multiple_of(6));
235235

236236
// Length of actual content in measure. `remove_space_between_notes` will reduce this for example
237237
let mut measure_content_len = ticks_in_measure;
@@ -299,7 +299,7 @@ impl MuxmlGenerator {
299299
}
300300
// Try to simplify e.g 8/8 to 4/4
301301
let (mut measure_enumerator, mut measure_denominator) = (measure_content_len, 8);
302-
if self.settings.simplify_time_signature && measure_content_len % 2 == 0 {
302+
if self.settings.simplify_time_signature && measure_content_len.is_multiple_of(2) {
303303
measure_enumerator /= 2;
304304
measure_denominator /= 2;
305305
}

src/parser/parser.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use super::{
77
use crate::{
88
backend::errors::backend_error::BackendError, parser::tab_element::TabElementError, ParseLines,
99
};
10-
use std::ops::RangeInclusive;
10+
use std::{array, ops::RangeInclusive};
1111

1212
pub fn line_is_valid(line: &str) -> bool {
1313
let line = line.trim();
@@ -74,6 +74,7 @@ impl ParseResult {
7474
bufs.concat()
7575
}
7676
}
77+
7778
pub fn parse<L: ParseLines>(lines: &L) -> ParseResult {
7879
let mut r = ParseResult::new();
7980
let mut part_first_line = 0;
@@ -94,7 +95,8 @@ pub fn parse<L: ParseLines>(lines: &L) -> ParseResult {
9495
let _part = span!(Level::DEBUG, "parsing part", ?range);
9596
let _part = _part.enter();
9697
r.offsets.push((part_first_line as u32, r.tick_stream.len() as u32));
97-
let mut part: Vec<&str> = range.map(|s| lines.get_line(s).trim()).collect(); // TODO: check if this is slow
98+
let mut part: [&str; 6] =
99+
array::from_fn(|i| part_first_line + i).map(|s| lines.get_line(s).trim()); // TODO: check if this is slow
98100

99101
// The current tick in THIS PART
100102
let mut tick = 0;
@@ -311,7 +313,7 @@ pub fn source_location_from_stream(r: &ParseResult, tick_location: u32) -> (u32,
311313
(actual_line, offset_on_line)
312314
}
313315

314-
pub fn dump_source(input: &Vec<&str>) -> String {
316+
pub fn dump_source(input: &[&str]) -> String {
315317
use itertools::Itertools;
316318
std::iter::once(&"").chain(input.iter()).join("\n")
317319
}

0 commit comments

Comments
 (0)