Optimize op-assignment statement.

This commit is contained in:
Stephen Chung
2020-05-25 20:14:31 +08:00
parent fca140ef55
commit 95e67c48bd
11 changed files with 341 additions and 234 deletions

View File

@@ -53,6 +53,10 @@ def_package!(crate:BasicArrayPackage:"Basic array utilities.", lib, {
x.extend(y);
Ok(())
});
lib.set_fn_2_mut("+=", |x: &mut Array, y: Array| {
x.extend(y);
Ok(())
});
lib.set_fn_2(
"+",
|mut x: Array, y: Array| {

View File

@@ -42,6 +42,15 @@ def_package!(crate:BasicMapPackage:"Basic object map utilities.", lib, {
Ok(())
},
);
lib.set_fn_2_mut(
"+=",
|map1: &mut Map, map2: Map| {
map2.into_iter().for_each(|(key, value)| {
map1.insert(key, value);
});
Ok(())
},
);
lib.set_fn_2(
"+",
|mut map1: Map, map2: Map| {

View File

@@ -105,10 +105,24 @@ def_package!(crate:BasicStringPackage:"Basic string utilities, including printin
Ok(s.into())
},
);
lib.set_fn_2_mut("+=", |s: &mut ImmutableString, ch: char| {
shared_make_mut(s).push(ch);
Ok(())
});
lib.set_fn_2_mut("append", |s: &mut ImmutableString, ch: char| {
shared_make_mut(s).push(ch);
Ok(())
});
lib.set_fn_2_mut(
"+=",
|s: &mut ImmutableString, s2: ImmutableString| {
if !s2.is_empty() {
shared_make_mut(s).push_str(s2.as_str());
}
Ok(())
}
);
lib.set_fn_2_mut(
"append",
|s: &mut ImmutableString, s2: ImmutableString| {