Skip to content

Commit 1fc9f98

Browse files
authored
chore: call shrink_to_fit afte parsing source maps (#242)
1 parent 4fb2951 commit 1fc9f98

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

crates/artifacts/solc/src/sourcemap.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -556,20 +556,23 @@ enum State {
556556

557557
impl State {
558558
fn advance(&mut self, pos: usize) -> Result<(), SyntaxError> {
559-
match self {
560-
Self::Offset => *self = Self::Length,
561-
Self::Length => *self = Self::Index,
562-
Self::Index => *self = Self::Jmp,
563-
Self::Jmp => *self = Self::Modifier,
559+
*self = match self {
560+
Self::Offset => Self::Length,
561+
Self::Length => Self::Index,
562+
Self::Index => Self::Jmp,
563+
Self::Jmp => Self::Modifier,
564564
Self::Modifier => return Err(SyntaxError::new(pos, "unexpected colon")),
565-
}
565+
};
566566
Ok(())
567567
}
568568
}
569569

570-
/// Parses a source map
570+
/// Parses a source map.
571571
pub fn parse(input: &str) -> Result<SourceMap, SyntaxError> {
572-
Parser::new(input).collect()
572+
Parser::new(input).collect::<Result<SourceMap, SyntaxError>>().map(|mut v| {
573+
v.shrink_to_fit();
574+
v
575+
})
573576
}
574577

575578
#[cfg(test)]

crates/compilers/src/compilers/solc/compiler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ fn version_from_output(output: Output) -> Result<Version> {
615615
let version = stdout
616616
.lines()
617617
.filter(|l| !l.trim().is_empty())
618-
.last()
618+
.next_back()
619619
.ok_or_else(|| SolcError::msg("Version not found in Solc output"))?;
620620
// NOTE: semver doesn't like `+` in g++ in build metadata which is invalid semver
621621
Ok(Version::from_str(&version.trim_start_matches("Version: ").replace(".g++", ".gcc"))?)

0 commit comments

Comments
 (0)