Diff
Modified: trunk/Source/_javascript_Core/ChangeLog (179790 => 179791)
--- trunk/Source/_javascript_Core/ChangeLog 2015-02-08 01:31:58 UTC (rev 179790)
+++ trunk/Source/_javascript_Core/ChangeLog 2015-02-08 02:28:48 UTC (rev 179791)
@@ -1,3 +1,12 @@
+2015-02-07 Chris Dumez <[email protected]>
+
+ Add Vector::removeFirstMatching() / removeAllMatching() methods taking lambda functions
+ https://bugs.webkit.org/show_bug.cgi?id=141321
+
+ Reviewed by Darin Adler.
+
+ Use new Vector::removeFirstMatching() / removeAllMatching() methods.
+
2015-02-06 Filip Pizlo <[email protected]>
DFG SSA shouldn't have SetArgument nodes
Modified: trunk/Source/_javascript_Core/profiler/ProfileNode.cpp (179790 => 179791)
--- trunk/Source/_javascript_Core/profiler/ProfileNode.cpp 2015-02-08 01:31:58 UTC (rev 179790)
+++ trunk/Source/_javascript_Core/profiler/ProfileNode.cpp 2015-02-08 02:28:48 UTC (rev 179791)
@@ -75,12 +75,9 @@
if (!node)
return;
- for (size_t i = 0; i < m_children.size(); ++i) {
- if (*node == m_children[i].get()) {
- m_children.remove(i);
- break;
- }
- }
+ m_children.removeFirstMatching([node] (const RefPtr<ProfileNode>& current) {
+ return *node == current.get();
+ });
#ifndef NDEBUG
size_t size = m_children.size();
Modified: trunk/Source/WTF/ChangeLog (179790 => 179791)
--- trunk/Source/WTF/ChangeLog 2015-02-08 01:31:58 UTC (rev 179790)
+++ trunk/Source/WTF/ChangeLog 2015-02-08 02:28:48 UTC (rev 179791)
@@ -1,3 +1,17 @@
+2015-02-07 Chris Dumez <[email protected]>
+
+ Add Vector::removeFirstMatching() / removeAllMatching() methods taking lambda functions
+ https://bugs.webkit.org/show_bug.cgi?id=141321
+
+ Reviewed by Darin Adler.
+
+ Add Vector::removeFirstMatching() / removeAllMatching() methods taking
+ lambda functions to match the element(s) to remove. This simplifies the
+ code a bit. Vector::removeAllMatching() is also more efficient than the
+ manual removal alternative.
+
+ * wtf/Vector.h:
+
2015-02-06 Commit Queue <[email protected]>
Unreviewed, rolling out r179743.
Modified: trunk/Source/WTF/wtf/Vector.h (179790 => 179791)
--- trunk/Source/WTF/wtf/Vector.h 2015-02-08 01:31:58 UTC (rev 179790)
+++ trunk/Source/WTF/wtf/Vector.h 2015-02-08 02:28:48 UTC (rev 179791)
@@ -736,7 +736,9 @@
void remove(size_t position);
void remove(size_t position, size_t length);
template<typename U> bool removeFirst(const U&);
+ template<typename MatchFunction> bool removeFirstMatching(const MatchFunction&);
template<typename U> unsigned removeAll(const U&);
+ template<typename MatchFunction> unsigned removeAllMatching(const MatchFunction&);
void removeLast()
{
@@ -1314,10 +1316,20 @@
template<typename U>
inline bool Vector<T, inlineCapacity, OverflowHandler>::removeFirst(const U& value)
{
- size_t index = find(value);
- if (index != notFound) {
- remove(index);
- return true;
+ return removeFirstMatching([&value] (const T& current) {
+ return current == value;
+ });
+}
+
+template<typename T, size_t inlineCapacity, typename OverflowHandler>
+template<typename MatchFunction>
+inline bool Vector<T, inlineCapacity, OverflowHandler>::removeFirstMatching(const MatchFunction& matches)
+{
+ for (size_t i = 0; i < size(); ++i) {
+ if (matches(at(i))) {
+ remove(i);
+ return true;
+ }
}
return false;
}
@@ -1326,11 +1338,20 @@
template<typename U>
inline unsigned Vector<T, inlineCapacity, OverflowHandler>::removeAll(const U& value)
{
+ return removeAllMatching([&value] (const T& current) {
+ return current == value;
+ });
+}
+
+template<typename T, size_t inlineCapacity, typename OverflowHandler>
+template<typename MatchFunction>
+inline unsigned Vector<T, inlineCapacity, OverflowHandler>::removeAllMatching(const MatchFunction& matches)
+{
iterator holeBegin = end();
iterator holeEnd = end();
unsigned matchCount = 0;
for (auto it = begin(), itEnd = end(); it != itEnd; ++it) {
- if (*it == value) {
+ if (matches(*it)) {
if (holeBegin == end())
holeBegin = it;
else if (holeEnd != it) {
Modified: trunk/Source/WebCore/ChangeLog (179790 => 179791)
--- trunk/Source/WebCore/ChangeLog 2015-02-08 01:31:58 UTC (rev 179790)
+++ trunk/Source/WebCore/ChangeLog 2015-02-08 02:28:48 UTC (rev 179791)
@@ -1,3 +1,12 @@
+2015-02-07 Chris Dumez <[email protected]>
+
+ Add Vector::removeFirstMatching() / removeAllMatching() methods taking lambda functions
+ https://bugs.webkit.org/show_bug.cgi?id=141321
+
+ Reviewed by Darin Adler.
+
+ Use new Vector::removeFirstMatching() / removeAllMatching() methods.
+
2015-02-07 Darin Adler <[email protected]>
Stop dispatching events to with SVGElementInstance objects as their targets
Modified: trunk/Source/WebCore/css/CSSParser.cpp (179790 => 179791)
--- trunk/Source/WebCore/css/CSSParser.cpp 2015-02-08 01:31:58 UTC (rev 179790)
+++ trunk/Source/WebCore/css/CSSParser.cpp 2015-02-08 02:28:48 UTC (rev 179791)
@@ -12077,14 +12077,9 @@
void CSSParser::deleteFontFaceOnlyValues()
{
ASSERT(m_hasFontFaceOnlyValues);
- for (unsigned i = 0; i < m_parsedProperties.size();) {
- CSSProperty& property = m_parsedProperties[i];
- if (property.id() == CSSPropertyFontVariant && property.value()->isValueList()) {
- m_parsedProperties.remove(i);
- continue;
- }
- ++i;
- }
+ m_parsedProperties.removeAllMatching([] (const CSSProperty& property) {
+ return property.id() == CSSPropertyFontVariant && property.value()->isValueList();
+ });
}
PassRefPtr<StyleKeyframe> CSSParser::createKeyframe(CSSParserValueList& keys)
Modified: trunk/Source/WebCore/css/CSSValueList.cpp (179790 => 179791)
--- trunk/Source/WebCore/css/CSSValueList.cpp 2015-02-08 01:31:58 UTC (rev 179790)
+++ trunk/Source/WebCore/css/CSSValueList.cpp 2015-02-08 02:28:48 UTC (rev 179791)
@@ -50,21 +50,15 @@
}
}
-bool CSSValueList::removeAll(CSSValue* val)
+bool CSSValueList::removeAll(CSSValue* value)
{
// FIXME: Why even take a pointer?
- if (!val)
+ if (!value)
return false;
- bool found = false;
- for (unsigned i = 0; i < m_values.size(); ++i) {
- if (m_values[i].get().equals(*val)) {
- m_values.remove(i);
- found = true;
- }
- }
-
- return found;
+ return m_values.removeAllMatching([value] (const Ref<CSSValue>& current) {
+ return current->equals(*value);
+ }) > 0;
}
bool CSSValueList::hasValue(CSSValue* val) const
Modified: trunk/Source/WebCore/css/MediaList.cpp (179790 => 179791)
--- trunk/Source/WebCore/css/MediaList.cpp 2015-02-08 01:31:58 UTC (rev 179790)
+++ trunk/Source/WebCore/css/MediaList.cpp 2015-02-08 02:28:48 UTC (rev 179791)
@@ -185,14 +185,9 @@
if (!parsedQuery)
return false;
- for (size_t i = 0; i < m_queries.size(); ++i) {
- MediaQuery* query = m_queries[i].get();
- if (*query == *parsedQuery) {
- m_queries.remove(i);
- return true;
- }
- }
- return false;
+ return m_queries.removeFirstMatching([&parsedQuery] (const std::unique_ptr<MediaQuery>& query) {
+ return *query == *parsedQuery;
+ });
}
void MediaQuerySet::addMediaQuery(std::unique_ptr<MediaQuery> mediaQuery)
Modified: trunk/Source/WebCore/css/MediaQueryMatcher.cpp (179790 => 179791)
--- trunk/Source/WebCore/css/MediaQueryMatcher.cpp 2015-02-08 01:31:58 UTC (rev 179790)
+++ trunk/Source/WebCore/css/MediaQueryMatcher.cpp 2015-02-08 02:28:48 UTC (rev 179791)
@@ -130,12 +130,9 @@
if (!m_document)
return;
- for (size_t i = 0; i < m_listeners.size(); ++i) {
- if (*m_listeners[i]->listener() == *listener && m_listeners[i]->query() == query) {
- m_listeners.remove(i);
- return;
- }
- }
+ m_listeners.removeFirstMatching([listener, query] (const std::unique_ptr<Listener>& current) {
+ return *current->listener() == *listener && current->query() == query;
+ });
}
void MediaQueryMatcher::styleResolverChanged()
Modified: trunk/Source/WebCore/css/StyleResolver.cpp (179790 => 179791)
--- trunk/Source/WebCore/css/StyleResolver.cpp 2015-02-08 01:31:58 UTC (rev 179790)
+++ trunk/Source/WebCore/css/StyleResolver.cpp 2015-02-08 02:28:48 UTC (rev 179791)
@@ -1191,10 +1191,9 @@
}
Vector<RefPtr<MaskImageOperation>>& pendingResources = m_state.maskImagesWithPendingSVGDocuments();
- for (int i = pendingResources.size() - 1; i >= 0; i--) {
- if (removedExternalResources.contains(pendingResources[i]))
- pendingResources.remove(i);
- }
+ pendingResources.removeAllMatching([&removedExternalResources] (const RefPtr<MaskImageOperation>& resource) {
+ return removedExternalResources.contains(resource);
+ });
}
}
Modified: trunk/Source/WebCore/dom/Element.cpp (179790 => 179791)
--- trunk/Source/WebCore/dom/Element.cpp 2015-02-08 01:31:58 UTC (rev 179790)
+++ trunk/Source/WebCore/dom/Element.cpp 2015-02-08 02:28:48 UTC (rev 179791)
@@ -2965,16 +2965,13 @@
ASSERT(hasSyntheticAttrChildNodes());
attrNode->detachFromElementWithValue(value);
- auto* attrNodeList = attrNodeListForElement(*this);
- for (unsigned i = 0; i < attrNodeList->size(); ++i) {
- if (attrNodeList->at(i)->qualifiedName() == attrNode->qualifiedName()) {
- attrNodeList->remove(i);
- if (attrNodeList->isEmpty())
- removeAttrNodeListForElement(*this);
- return;
- }
- }
- ASSERT_NOT_REACHED();
+ auto& attrNodeList = *attrNodeListForElement(*this);
+ bool found = attrNodeList.removeFirstMatching([attrNode] (const RefPtr<Attr>& attribute) {
+ return attribute->qualifiedName() == attrNode->qualifiedName();
+ });
+ ASSERT_UNUSED(found, found);
+ if (attrNodeList.isEmpty())
+ removeAttrNodeListForElement(*this);
}
void Element::detachAllAttrNodesFromElement()
Modified: trunk/Source/WebCore/dom/EventListenerMap.cpp (179790 => 179791)
--- trunk/Source/WebCore/dom/EventListenerMap.cpp 2015-02-08 01:31:58 UTC (rev 179790)
+++ trunk/Source/WebCore/dom/EventListenerMap.cpp 2015-02-08 02:28:48 UTC (rev 179791)
@@ -156,21 +156,14 @@
return m_entries[i].second.get();
}
- return 0;
+ return nullptr;
}
-static void removeFirstListenerCreatedFromMarkup(EventListenerVector* listenerVector)
+static void removeFirstListenerCreatedFromMarkup(EventListenerVector& listenerVector)
{
- bool foundListener = false;
-
- for (size_t i = 0; i < listenerVector->size(); ++i) {
- if (!listenerVector->at(i).listener->wasCreatedFromMarkup())
- continue;
- foundListener = true;
- listenerVector->remove(i);
- break;
- }
-
+ bool foundListener = listenerVector.removeFirstMatching([] (const RegisteredEventListener& listener) {
+ return listener.listener->wasCreatedFromMarkup();
+ });
ASSERT_UNUSED(foundListener, foundListener);
}
@@ -180,7 +173,7 @@
for (unsigned i = 0; i < m_entries.size(); ++i) {
if (m_entries[i].first == eventType) {
- removeFirstListenerCreatedFromMarkup(m_entries[i].second.get());
+ removeFirstListenerCreatedFromMarkup(*m_entries[i].second);
if (m_entries[i].second->isEmpty())
m_entries.remove(i);
return;
Modified: trunk/Source/WebCore/dom/Node.cpp (179790 => 179791)
--- trunk/Source/WebCore/dom/Node.cpp 2015-02-08 01:31:58 UTC (rev 179790)
+++ trunk/Source/WebCore/dom/Node.cpp 2015-02-08 02:28:48 UTC (rev 179791)
@@ -1952,12 +1952,9 @@
if (!registry)
return;
- for (size_t i = 0; i < registry->size(); ++i) {
- if (registry->at(i).get() == registration) {
- registry->remove(i);
- return;
- }
- }
+ registry->removeFirstMatching([registration] (const std::unique_ptr<MutationObserverRegistration>& current) {
+ return current.get() == registration;
+ });
}
void Node::registerTransientMutationObserver(MutationObserverRegistration* registration)
Modified: trunk/Source/WebCore/html/parser/HTMLTreeBuilder.cpp (179790 => 179791)
--- trunk/Source/WebCore/html/parser/HTMLTreeBuilder.cpp 2015-02-08 01:31:58 UTC (rev 179790)
+++ trunk/Source/WebCore/html/parser/HTMLTreeBuilder.cpp 2015-02-08 02:28:48 UTC (rev 179791)
@@ -441,11 +441,10 @@
Vector<Attribute> HTMLTreeBuilder::attributesForIsindexInput(AtomicHTMLToken& token)
{
Vector<Attribute> attributes = token.attributes();
- for (int i = attributes.size() - 1; i >= 0; --i) {
- const QualifiedName& name = attributes.at(i).name();
- if (name.matches(nameAttr) || name.matches(actionAttr) || name.matches(promptAttr))
- attributes.remove(i);
- }
+ attributes.removeAllMatching([] (const Attribute& attribute) {
+ const QualifiedName& name = attribute.name();
+ return name.matches(nameAttr) || name.matches(actionAttr) || name.matches(promptAttr);
+ });
attributes.append(Attribute(nameAttr, isindexTag.localName()));
return attributes;
Modified: trunk/Source/WebCore/platform/graphics/texmap/TextureMapperAnimation.cpp (179790 => 179791)
--- trunk/Source/WebCore/platform/graphics/texmap/TextureMapperAnimation.cpp 2015-02-08 01:31:58 UTC (rev 179790)
+++ trunk/Source/WebCore/platform/graphics/texmap/TextureMapperAnimation.cpp 2015-02-08 02:28:48 UTC (rev 179791)
@@ -365,18 +365,16 @@
void TextureMapperAnimations::remove(const String& name)
{
- for (int i = m_animations.size() - 1; i >= 0; --i) {
- if (m_animations[i].name() == name)
- m_animations.remove(i);
- }
+ m_animations.removeAllMatching([&name] (const TextureMapperAnimation& animation) {
+ return animation.name() == name;
+ });
}
void TextureMapperAnimations::remove(const String& name, AnimatedPropertyID property)
{
- for (int i = m_animations.size() - 1; i >= 0; --i) {
- if (m_animations[i].name() == name && m_animations[i].property() == property)
- m_animations.remove(i);
- }
+ m_animations.removeAllMatching([&name, property] (const TextureMapperAnimation& animation) {
+ return animation.name() == name && animation.property() == property;
+ });
}
void TextureMapperAnimations::apply(TextureMapperAnimation::Client* client)
Modified: trunk/Source/WebCore/svg/animation/SVGSMILElement.cpp (179790 => 179791)
--- trunk/Source/WebCore/svg/animation/SVGSMILElement.cpp 2015-02-08 01:31:58 UTC (rev 179790)
+++ trunk/Source/WebCore/svg/animation/SVGSMILElement.cpp 2015-02-08 02:28:48 UTC (rev 179791)
@@ -214,10 +214,9 @@
static inline void clearTimesWithDynamicOrigins(Vector<SMILTimeWithOrigin>& timeList)
{
- for (int i = timeList.size() - 1; i >= 0; --i) {
- if (timeList[i].originIsScript())
- timeList.remove(i);
- }
+ timeList.removeAllMatching([] (const SMILTimeWithOrigin& time) {
+ return time.originIsScript();
+ });
}
void SVGSMILElement::reset()
Modified: trunk/Source/WebKit/win/ChangeLog (179790 => 179791)
--- trunk/Source/WebKit/win/ChangeLog 2015-02-08 01:31:58 UTC (rev 179790)
+++ trunk/Source/WebKit/win/ChangeLog 2015-02-08 02:28:48 UTC (rev 179791)
@@ -1,3 +1,12 @@
+2015-02-07 Chris Dumez <[email protected]>
+
+ Add Vector::removeFirstMatching() / removeAllMatching() methods taking lambda functions
+ https://bugs.webkit.org/show_bug.cgi?id=141321
+
+ Reviewed by Darin Adler.
+
+ Use new Vector::removeFirstMatching() / removeAllMatching() methods.
+
2015-02-02 Chris Dumez <[email protected]>
Access MemoryCache singleton using MemoryCache::singleton()
Modified: trunk/Source/WebKit/win/WebNotificationCenter.cpp (179790 => 179791)
--- trunk/Source/WebKit/win/WebNotificationCenter.cpp 2015-02-08 01:31:58 UTC (rev 179790)
+++ trunk/Source/WebKit/win/WebNotificationCenter.cpp 2015-02-08 02:28:48 UTC (rev 179791)
@@ -200,15 +200,11 @@
ObjectObserverList& observerList = it->value;
ObserverListIterator end = observerList.end();
- int i = 0;
- for (ObserverListIterator it2 = observerList.begin(); it2 != end; ++it2, ++i) {
- IUnknown* observedObject = it2->first.get();
- IWebNotificationObserver* observer = it2->second.get();
- if (observer == anObserver && (!anObject || anObject == observedObject)) {
- observerList.remove(i);
- break;
- }
- }
+ observerList.removeFirstMatching([anObject, anObserver] (const ObjectObserverPair& pair) {
+ IUnknown* observedObject = pair.first.get();
+ IWebNotificationObserver* observer = pair.second.get();
+ return observer == anObserver && (!anObject || anObject == observedObject);
+ });
if (observerList.isEmpty())
d->m_mappedObservers.remove(name);
Modified: trunk/Source/WebKit2/ChangeLog (179790 => 179791)
--- trunk/Source/WebKit2/ChangeLog 2015-02-08 01:31:58 UTC (rev 179790)
+++ trunk/Source/WebKit2/ChangeLog 2015-02-08 02:28:48 UTC (rev 179791)
@@ -1,3 +1,12 @@
+2015-02-07 Chris Dumez <[email protected]>
+
+ Add Vector::removeFirstMatching() / removeAllMatching() methods taking lambda functions
+ https://bugs.webkit.org/show_bug.cgi?id=141321
+
+ Reviewed by Darin Adler.
+
+ Use new Vector::removeFirstMatching() / removeAllMatching() methods.
+
2015-02-07 Tim Horton <[email protected]>
Add API::HistoryClient and split some things out of API::NavigationClient
Modified: trunk/Source/WebKit2/WebProcess/WebPage/mac/PlatformCALayerRemote.cpp (179790 => 179791)
--- trunk/Source/WebKit2/WebProcess/WebPage/mac/PlatformCALayerRemote.cpp 2015-02-08 01:31:58 UTC (rev 179790)
+++ trunk/Source/WebKit2/WebProcess/WebPage/mac/PlatformCALayerRemote.cpp 2015-02-08 02:28:48 UTC (rev 179791)
@@ -350,12 +350,9 @@
void PlatformCALayerRemote::removeAnimationForKey(const String& key)
{
if (m_animations.remove(key)) {
- for (size_t i = 0; i < m_properties.addedAnimations.size(); ++i) {
- if (m_properties.addedAnimations[i].first == key) {
- m_properties.addedAnimations.remove(i);
- break;
- }
- }
+ m_properties.addedAnimations.removeFirstMatching([&key] (const std::pair<String, PlatformCAAnimationRemote::Properties>& pair) {
+ return pair.first == key;
+ });
}
m_properties.keyPathsOfAnimationsToRemove.add(key);
m_properties.notePropertiesChanged(RemoteLayerTreeTransaction::AnimationsChanged);
Modified: trunk/Tools/ChangeLog (179790 => 179791)
--- trunk/Tools/ChangeLog 2015-02-08 01:31:58 UTC (rev 179790)
+++ trunk/Tools/ChangeLog 2015-02-08 02:28:48 UTC (rev 179791)
@@ -1,3 +1,12 @@
+2015-02-07 Chris Dumez <[email protected]>
+
+ Add Vector::removeFirstMatching() / removeAllMatching() methods taking lambda functions
+ https://bugs.webkit.org/show_bug.cgi?id=141321
+
+ Reviewed by Darin Adler.
+
+ Use new Vector::removeFirstMatching() / removeAllMatching() methods.
+
2015-02-07 David Kilzer <[email protected]>
[iOS] Make Simulator class testable
Modified: trunk/Tools/TestWebKitAPI/Tests/WTF/Vector.cpp (179790 => 179791)
--- trunk/Tools/TestWebKitAPI/Tests/WTF/Vector.cpp 2015-02-08 01:31:58 UTC (rev 179790)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/Vector.cpp 2015-02-08 02:28:48 UTC (rev 179791)
@@ -463,4 +463,58 @@
EXPECT_TRUE(v2 == vExpected);
}
+TEST(WTF_Vector, RemoveFirstMatching)
+{
+ Vector<int> v;
+ EXPECT_TRUE(v.isEmpty());
+ EXPECT_FALSE(v.removeFirstMatching([] (int value) { return value > 0; }));
+ EXPECT_FALSE(v.removeFirstMatching([] (int) { return true; }));
+ EXPECT_FALSE(v.removeFirstMatching([] (int) { return false; }));
+
+ v = {3, 1, 2, 1, 2, 1, 2, 2, 1, 1, 1, 3};
+ EXPECT_EQ(12U, v.size());
+ EXPECT_FALSE(v.removeFirstMatching([] (int) { return false; }));
+ EXPECT_EQ(12U, v.size());
+ EXPECT_FALSE(v.removeFirstMatching([] (int value) { return value < 0; }));
+ EXPECT_EQ(12U, v.size());
+ EXPECT_TRUE(v.removeFirstMatching([] (int value) { return value < 3; }));
+ EXPECT_EQ(11U, v.size());
+ EXPECT_TRUE(v == Vector<int>({3, 2, 1, 2, 1, 2, 2, 1, 1, 1, 3}));
+ EXPECT_TRUE(v.removeFirstMatching([] (int value) { return value > 2; }));
+ EXPECT_EQ(10U, v.size());
+ EXPECT_TRUE(v == Vector<int>({2, 1, 2, 1, 2, 2, 1, 1, 1, 3}));
+ EXPECT_TRUE(v.removeFirstMatching([] (int value) { return value > 2; }));
+ EXPECT_EQ(9U, v.size());
+ EXPECT_TRUE(v == Vector<int>({2, 1, 2, 1, 2, 2, 1, 1, 1}));
+}
+
+TEST(WTF_Vector, RemoveAllMatching)
+{
+ Vector<int> v;
+ EXPECT_TRUE(v.isEmpty());
+ EXPECT_FALSE(v.removeAllMatching([] (int value) { return value > 0; }));
+ EXPECT_FALSE(v.removeAllMatching([] (int) { return true; }));
+ EXPECT_FALSE(v.removeAllMatching([] (int) { return false; }));
+
+ v = {3, 1, 2, 1, 2, 1, 2, 2, 1, 1, 1, 3};
+ EXPECT_EQ(12U, v.size());
+ EXPECT_EQ(0U, v.removeAllMatching([] (int) { return false; }));
+ EXPECT_EQ(12U, v.size());
+ EXPECT_EQ(0U, v.removeAllMatching([] (int value) { return value < 0; }));
+ EXPECT_EQ(12U, v.size());
+ EXPECT_EQ(12U, v.removeAllMatching([] (int value) { return value > 0; }));
+ EXPECT_TRUE(v.isEmpty());
+
+ v = {3, 1, 2, 1, 2, 1, 3, 2, 2, 1, 1, 1, 3};
+ EXPECT_EQ(13U, v.size());
+ EXPECT_EQ(3U, v.removeAllMatching([] (int value) { return value > 2; }));
+ EXPECT_EQ(10U, v.size());
+ EXPECT_TRUE(v == Vector<int>({1, 2, 1, 2, 1, 2, 2, 1, 1, 1}));
+ EXPECT_EQ(6U, v.removeAllMatching([] (int value) { return value != 2; }));
+ EXPECT_EQ(4U, v.size());
+ EXPECT_TRUE(v == Vector<int>({2, 2, 2, 2}));
+ EXPECT_EQ(4U, v.removeAllMatching([] (int value) { return value == 2; }));
+ EXPECT_TRUE(v.isEmpty());
+}
+
} // namespace TestWebKitAPI
Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp (179790 => 179791)
--- trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp 2015-02-08 01:31:58 UTC (rev 179790)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp 2015-02-08 02:28:48 UTC (rev 179791)
@@ -109,13 +109,9 @@
void InjectedBundle::willDestroyPage(WKBundlePageRef page)
{
- size_t size = m_pages.size();
- for (size_t i = 0; i < size; ++i) {
- if (m_pages[i]->page() == page) {
- m_pages.remove(i);
- break;
- }
- }
+ m_pages.removeFirstMatching([page] (const std::unique_ptr<InjectedBundlePage>& current) {
+ return current->page() == page;
+ });
}
void InjectedBundle::didInitializePageGroup(WKBundlePageGroupRef pageGroup)