Skip to content

Commit 9d06416

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

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
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: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ impl ParseResult {
7474
bufs.concat()
7575
}
7676
}
77+
78+
/// stupid helper function, used because Rust doesn't currently let you collect into an array
79+
fn line_indices(idx: usize) -> [usize; 6] {
80+
[idx, idx + 1, idx + 2, idx + 3, idx + 4, idx + 5]
81+
}
7782
pub fn parse<L: ParseLines>(lines: &L) -> ParseResult {
7883
let mut r = ParseResult::new();
7984
let mut part_first_line = 0;
@@ -94,7 +99,7 @@ pub fn parse<L: ParseLines>(lines: &L) -> ParseResult {
9499
let _part = span!(Level::DEBUG, "parsing part", ?range);
95100
let _part = _part.enter();
96101
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
102+
let mut part: [&str; 6] = line_indices(part_first_line).map(|s| lines.get_line(s).trim()); // TODO: check if this is slow
98103

99104
// The current tick in THIS PART
100105
let mut tick = 0;
@@ -311,7 +316,7 @@ pub fn source_location_from_stream(r: &ParseResult, tick_location: u32) -> (u32,
311316
(actual_line, offset_on_line)
312317
}
313318

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

0 commit comments

Comments
 (0)