Refactor.

This commit is contained in:
Stephen Chung
2022-10-10 16:46:35 +08:00
parent 796206f293
commit d6b0f99781
15 changed files with 161 additions and 166 deletions

View File

@@ -82,10 +82,11 @@ mod map_functions {
/// print(m); // prints "#{a: 1, b: 42, c: 3, x: 0}"
/// ```
pub fn set(map: &mut Map, property: &str, value: Dynamic) {
if let Some(value_ref) = map.get_mut(property) {
*value_ref = value;
} else {
map.insert(property.into(), value);
match map.get_mut(property) {
Some(value_ref) => *value_ref = value,
_ => {
map.insert(property.into(), value);
}
}
}
/// Clear the object map.

View File

@@ -239,10 +239,9 @@ mod string_functions {
/// Clear the string, making it empty.
pub fn clear(string: &mut ImmutableString) {
if !string.is_empty() {
if let Some(s) = string.get_mut() {
s.clear();
} else {
*string = ImmutableString::new();
match string.get_mut() {
Some(s) => s.clear(),
_ => *string = ImmutableString::new(),
}
}
}
@@ -287,17 +286,20 @@ mod string_functions {
/// print(text); // prints "hello"
/// ```
pub fn trim(string: &mut ImmutableString) {
if let Some(s) = string.get_mut() {
let trimmed = s.trim();
match string.get_mut() {
Some(s) => {
let trimmed = s.trim();
if trimmed != s {
*s = trimmed.into();
if trimmed != s {
*s = trimmed.into();
}
}
} else {
let trimmed = string.trim();
None => {
let trimmed = string.trim();
if trimmed != string {
*string = trimmed.into();
if trimmed != string {
*string = trimmed.into();
}
}
}
}