Skip to content

Commit

Permalink
Refactor: Cleanup String.prototype.replace
Browse files Browse the repository at this point in the history
Sugestions by @HalidOdat in #629
  • Loading branch information
RageKnify committed Sep 1, 2020
1 parent 1ca0828 commit c258ebc
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions boa/src/builtins/string/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,10 +523,11 @@ impl String {
let units = third.to_digit(10).unwrap() as usize;
let nn = 10 * tens + units;
if nn == 0 || nn > m {
[Some(first), Some(second), chars.next()]
.iter()
.flatten()
.for_each(|ch: &char| result.push(*ch));
result.push(first);
result.push(second);
if Some(ch) = chars.next() {
result.push(ch);
}
} else {
let group = match caps.get(nn) {
Some(text) => text.as_str(),
Expand Down Expand Up @@ -558,7 +559,9 @@ impl String {
// $?, ? is none of the above
// we can consume second because it isn't $
result.push(first);
second.iter().for_each(|ch: &char| result.push(*ch));
if let Some(second) = second {
result.push(second);
}
}
}
} else {
Expand Down

0 comments on commit c258ebc

Please sign in to comment.