Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 3cee41d

Browse files
author
Mats Palmgren
committed
Bug 1376278 - Use LookupForAdd instead of Get+Put, and remove a couple of Remove calls before Put, to avoid unnecessary hashtable lookups. r=froydnj
MozReview-Commit-ID: 3b1FSGUwqLy
1 parent 0b5b089 commit 3cee41d

1 file changed

Lines changed: 2 additions & 8 deletions

File tree

gfx/src/FilterSupport.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2132,7 +2132,6 @@ AttributeMap::GetType(FilterAttribute* aAttribute)
21322132
} \
21332133
void \
21342134
AttributeMap::Set(AttributeName aName, type aValue) { \
2135-
mMap.Remove(aName); \
21362135
mMap.Put(aName, new Attribute(aValue)); \
21372136
}
21382137

@@ -2144,7 +2143,6 @@ AttributeMap::GetType(FilterAttribute* aAttribute)
21442143
} \
21452144
void \
21462145
AttributeMap::Set(AttributeName aName, const className& aValue) { \
2147-
mMap.Remove(aName); \
21482146
mMap.Put(aName, new Attribute(aValue)); \
21492147
}
21502148

@@ -2166,18 +2164,14 @@ MAKE_ATTRIBUTE_HANDLERS_CLASS(AttributeMap)
21662164
const nsTArray<float>&
21672165
AttributeMap::GetFloats(AttributeName aName) const
21682166
{
2169-
Attribute* value = mMap.Get(aName);
2170-
if (!value) {
2171-
value = new Attribute(nullptr, 0);
2172-
mMap.Put(aName, value);
2173-
}
2167+
Attribute* value = mMap.LookupForAdd(aName).OrInsert(
2168+
[] () { return new Attribute(nullptr, 0); });
21742169
return value->AsFloats();
21752170
}
21762171

21772172
void
21782173
AttributeMap::Set(AttributeName aName, const float* aValues, int32_t aLength)
21792174
{
2180-
mMap.Remove(aName);
21812175
mMap.Put(aName, new Attribute(aValues, aLength));
21822176
}
21832177

0 commit comments

Comments
 (0)