diff options
author | Alan Wu <XrXr@users.noreply.github.com> | 2022-04-20 11:29:05 -0400 |
---|---|---|
committer | Alan Wu <XrXr@users.noreply.github.com> | 2022-04-27 11:00:22 -0400 |
commit | 932bfd0beb048efd22983a6de6fdf1a55e41de40 (patch) | |
tree | b96efcb881363465beac3c38653bcad0baf90332 /yjit/src/asm | |
parent | f90549cd38518231a6a74432fe1168c943a7cc18 (diff) |
YJIT: Make add_comment() more concise
Thanks to suggestions from Stranger6667 on GitHub.
Co-authored-by: Dmitry Dygalo <dmitry@dygalo.dev>
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/5826
Diffstat (limited to 'yjit/src/asm')
-rw-r--r-- | yjit/src/asm/mod.rs | 12 |
1 files changed, 3 insertions, 9 deletions
diff --git a/yjit/src/asm/mod.rs b/yjit/src/asm/mod.rs index 0d61cd654a..2d6736e0f4 100644 --- a/yjit/src/asm/mod.rs +++ b/yjit/src/asm/mod.rs @@ -156,19 +156,13 @@ impl CodeBlock { pub fn add_comment(&mut self, comment: &str) { if cfg!(feature = "asm_comments") { let cur_ptr = self.get_write_ptr().into_usize(); - let this_line_comments = self.asm_comments.get(&cur_ptr); // If there's no current list of comments for this line number, add one. - if this_line_comments.is_none() { - let new_comments = Vec::new(); - self.asm_comments.insert(cur_ptr, new_comments); - } - let this_line_comments = self.asm_comments.get_mut(&cur_ptr).unwrap(); + let this_line_comments = self.asm_comments.entry(cur_ptr).or_default(); // Unless this comment is the same as the last one at this same line, add it. - let string_comment = String::from(comment); - if this_line_comments.last() != Some(&string_comment) { - this_line_comments.push(string_comment); + if this_line_comments.last().map(String::as_str) != Some(comment) { + this_line_comments.push(comment.to_string()); } } } |