core: Made PropertyMap::insert take &str instead of String, as ownership isn't always needed

This commit is contained in:
Nathan Adams 2020-07-04 01:23:58 +02:00 committed by Mike Welsh
parent fb84999778
commit 938d644d7d
3 changed files with 9 additions and 10 deletions

View File

@ -438,7 +438,7 @@ impl<'gc> TObject<'gc> for ScriptObject<'gc> {
attributes: EnumSet<Attribute>,
) {
self.0.write(gc_context).values.insert(
name.to_owned(),
name,
Property::Virtual {
get,
set,
@ -458,7 +458,7 @@ impl<'gc> TObject<'gc> for ScriptObject<'gc> {
attributes: EnumSet<Attribute>,
) {
self.0.write(gc_context).values.insert(
name.to_owned(),
name,
Property::Virtual {
get,
set,
@ -475,11 +475,10 @@ impl<'gc> TObject<'gc> for ScriptObject<'gc> {
value: Value<'gc>,
attributes: EnumSet<Attribute>,
) {
self.0.write(gc_context).values.insert(
name.to_string(),
Property::Stored { value, attributes },
false,
);
self.0
.write(gc_context)
.values
.insert(name, Property::Stored { value, attributes }, false);
}
fn set_attributes(

View File

@ -598,7 +598,7 @@ impl<'gc> DisplayPropertyMap<'gc> {
set: Option<DisplaySetter<'gc>>,
) {
let prop = DisplayProperty { get, set };
self.0.insert(name.to_string(), prop, false);
self.0.insert(name, prop, false);
}
}

View File

@ -76,8 +76,8 @@ impl<V> PropertyMap<V> {
self.0.get_index(index).map(|(_, v)| v)
}
pub fn insert(&mut self, key: String, value: V, case_sensitive: bool) -> Option<V> {
match self.entry(&key, case_sensitive) {
pub fn insert(&mut self, key: &str, value: V, case_sensitive: bool) -> Option<V> {
match self.entry(key, case_sensitive) {
Entry::Occupied(entry) => Some(entry.insert(value)),
Entry::Vacant(entry) => {
entry.insert(value);