Skip to content

Commit

Permalink
Simplify.
Browse files Browse the repository at this point in the history
  • Loading branch information
ltratt committed Aug 6, 2020
1 parent 5b2ffdd commit 918d735
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions src/lib/vm/objects/string_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,18 +156,11 @@ impl String_ {
let mut new = String::new();
new.push_str(&self.s);
new.push_str(&other_str.s);
if self.chars_len.get() != usize::MAX && other_str.chars_len.get() != usize::MAX {
// If both strings have had their number of characters initialised then we can
// initialise the new string with its `chars_len` eagerly initialised.
let chars_len = self
.chars_len
.get()
.checked_add(other_str.chars_len.get())
.unwrap();
Ok(String_::new_str_chars_len(vm, new.into(), chars_len))
} else {
Ok(String_::new_str(vm, new.into()))
}
let chars_len = self
.chars_len
.get()
.saturating_add(other_str.chars_len.get());
Ok(String_::new_str_chars_len(vm, new.into(), chars_len))
}

pub fn substring(&self, vm: &mut VM, start: usize, end: usize) -> Result<Val, Box<VMError>> {
Expand Down

0 comments on commit 918d735

Please sign in to comment.