Changeset 179791 in webkit
- Timestamp:
- Feb 7, 2015 6:28:48 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 23 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r179767 r179791 1 2015-02-07 Chris Dumez <cdumez@apple.com> 2 3 Add Vector::removeFirstMatching() / removeAllMatching() methods taking lambda functions 4 https://bugs.webkit.org/show_bug.cgi?id=141321 5 6 Reviewed by Darin Adler. 7 8 Use new Vector::removeFirstMatching() / removeAllMatching() methods. 9 1 10 2015-02-06 Filip Pizlo <fpizlo@apple.com> 2 11 -
trunk/Source/JavaScriptCore/profiler/ProfileNode.cpp
r173262 r179791 76 76 return; 77 77 78 for (size_t i = 0; i < m_children.size(); ++i) { 79 if (*node == m_children[i].get()) { 80 m_children.remove(i); 81 break; 82 } 83 } 78 m_children.removeFirstMatching([node] (const RefPtr<ProfileNode>& current) { 79 return *node == current.get(); 80 }); 84 81 85 82 #ifndef NDEBUG -
trunk/Source/WTF/ChangeLog
r179751 r179791 1 2015-02-07 Chris Dumez <cdumez@apple.com> 2 3 Add Vector::removeFirstMatching() / removeAllMatching() methods taking lambda functions 4 https://bugs.webkit.org/show_bug.cgi?id=141321 5 6 Reviewed by Darin Adler. 7 8 Add Vector::removeFirstMatching() / removeAllMatching() methods taking 9 lambda functions to match the element(s) to remove. This simplifies the 10 code a bit. Vector::removeAllMatching() is also more efficient than the 11 manual removal alternative. 12 13 * wtf/Vector.h: 14 1 15 2015-02-06 Commit Queue <commit-queue@webkit.org> 2 16 -
trunk/Source/WTF/wtf/Vector.h
r179751 r179791 737 737 void remove(size_t position, size_t length); 738 738 template<typename U> bool removeFirst(const U&); 739 template<typename MatchFunction> bool removeFirstMatching(const MatchFunction&); 739 740 template<typename U> unsigned removeAll(const U&); 741 template<typename MatchFunction> unsigned removeAllMatching(const MatchFunction&); 740 742 741 743 void removeLast() … … 1315 1317 inline bool Vector<T, inlineCapacity, OverflowHandler>::removeFirst(const U& value) 1316 1318 { 1317 size_t index = find(value); 1318 if (index != notFound) { 1319 remove(index); 1320 return true; 1319 return removeFirstMatching([&value] (const T& current) { 1320 return current == value; 1321 }); 1322 } 1323 1324 template<typename T, size_t inlineCapacity, typename OverflowHandler> 1325 template<typename MatchFunction> 1326 inline bool Vector<T, inlineCapacity, OverflowHandler>::removeFirstMatching(const MatchFunction& matches) 1327 { 1328 for (size_t i = 0; i < size(); ++i) { 1329 if (matches(at(i))) { 1330 remove(i); 1331 return true; 1332 } 1321 1333 } 1322 1334 return false; … … 1326 1338 template<typename U> 1327 1339 inline unsigned Vector<T, inlineCapacity, OverflowHandler>::removeAll(const U& value) 1340 { 1341 return removeAllMatching([&value] (const T& current) { 1342 return current == value; 1343 }); 1344 } 1345 1346 template<typename T, size_t inlineCapacity, typename OverflowHandler> 1347 template<typename MatchFunction> 1348 inline unsigned Vector<T, inlineCapacity, OverflowHandler>::removeAllMatching(const MatchFunction& matches) 1328 1349 { 1329 1350 iterator holeBegin = end(); … … 1331 1352 unsigned matchCount = 0; 1332 1353 for (auto it = begin(), itEnd = end(); it != itEnd; ++it) { 1333 if ( *it == value) {1354 if (matches(*it)) { 1334 1355 if (holeBegin == end()) 1335 1356 holeBegin = it; -
trunk/Source/WebCore/ChangeLog
r179785 r179791 1 2015-02-07 Chris Dumez <cdumez@apple.com> 2 3 Add Vector::removeFirstMatching() / removeAllMatching() methods taking lambda functions 4 https://bugs.webkit.org/show_bug.cgi?id=141321 5 6 Reviewed by Darin Adler. 7 8 Use new Vector::removeFirstMatching() / removeAllMatching() methods. 9 1 10 2015-02-07 Darin Adler <darin@apple.com> 2 11 -
trunk/Source/WebCore/css/CSSParser.cpp
r179693 r179791 12078 12078 { 12079 12079 ASSERT(m_hasFontFaceOnlyValues); 12080 for (unsigned i = 0; i < m_parsedProperties.size();) { 12081 CSSProperty& property = m_parsedProperties[i]; 12082 if (property.id() == CSSPropertyFontVariant && property.value()->isValueList()) { 12083 m_parsedProperties.remove(i); 12084 continue; 12085 } 12086 ++i; 12087 } 12080 m_parsedProperties.removeAllMatching([] (const CSSProperty& property) { 12081 return property.id() == CSSPropertyFontVariant && property.value()->isValueList(); 12082 }); 12088 12083 } 12089 12084 -
trunk/Source/WebCore/css/CSSValueList.cpp
r175513 r179791 51 51 } 52 52 53 bool CSSValueList::removeAll(CSSValue* val )53 bool CSSValueList::removeAll(CSSValue* value) 54 54 { 55 55 // FIXME: Why even take a pointer? 56 if (!val )56 if (!value) 57 57 return false; 58 58 59 bool found = false; 60 for (unsigned i = 0; i < m_values.size(); ++i) { 61 if (m_values[i].get().equals(*val)) { 62 m_values.remove(i); 63 found = true; 64 } 65 } 66 67 return found; 59 return m_values.removeAllMatching([value] (const Ref<CSSValue>& current) { 60 return current->equals(*value); 61 }) > 0; 68 62 } 69 63 -
trunk/Source/WebCore/css/MediaList.cpp
r174300 r179791 186 186 return false; 187 187 188 for (size_t i = 0; i < m_queries.size(); ++i) { 189 MediaQuery* query = m_queries[i].get(); 190 if (*query == *parsedQuery) { 191 m_queries.remove(i); 192 return true; 193 } 194 } 195 return false; 188 return m_queries.removeFirstMatching([&parsedQuery] (const std::unique_ptr<MediaQuery>& query) { 189 return *query == *parsedQuery; 190 }); 196 191 } 197 192 -
trunk/Source/WebCore/css/MediaQueryMatcher.cpp
r165547 r179791 131 131 return; 132 132 133 for (size_t i = 0; i < m_listeners.size(); ++i) { 134 if (*m_listeners[i]->listener() == *listener && m_listeners[i]->query() == query) { 135 m_listeners.remove(i); 136 return; 137 } 138 } 133 m_listeners.removeFirstMatching([listener, query] (const std::unique_ptr<Listener>& current) { 134 return *current->listener() == *listener && current->query() == query; 135 }); 139 136 } 140 137 -
trunk/Source/WebCore/css/StyleResolver.cpp
r179368 r179791 1192 1192 1193 1193 Vector<RefPtr<MaskImageOperation>>& pendingResources = m_state.maskImagesWithPendingSVGDocuments(); 1194 for (int i = pendingResources.size() - 1; i >= 0; i--) { 1195 if (removedExternalResources.contains(pendingResources[i])) 1196 pendingResources.remove(i); 1197 } 1194 pendingResources.removeAllMatching([&removedExternalResources] (const RefPtr<MaskImageOperation>& resource) { 1195 return removedExternalResources.contains(resource); 1196 }); 1198 1197 } 1199 1198 } -
trunk/Source/WebCore/dom/Element.cpp
r179770 r179791 2966 2966 attrNode->detachFromElementWithValue(value); 2967 2967 2968 auto* attrNodeList = attrNodeListForElement(*this); 2969 for (unsigned i = 0; i < attrNodeList->size(); ++i) { 2970 if (attrNodeList->at(i)->qualifiedName() == attrNode->qualifiedName()) { 2971 attrNodeList->remove(i); 2972 if (attrNodeList->isEmpty()) 2973 removeAttrNodeListForElement(*this); 2974 return; 2975 } 2976 } 2977 ASSERT_NOT_REACHED(); 2968 auto& attrNodeList = *attrNodeListForElement(*this); 2969 bool found = attrNodeList.removeFirstMatching([attrNode] (const RefPtr<Attr>& attribute) { 2970 return attribute->qualifiedName() == attrNode->qualifiedName(); 2971 }); 2972 ASSERT_UNUSED(found, found); 2973 if (attrNodeList.isEmpty()) 2974 removeAttrNodeListForElement(*this); 2978 2975 } 2979 2976 -
trunk/Source/WebCore/dom/EventListenerMap.cpp
r173240 r179791 157 157 } 158 158 159 return 0; 160 } 161 162 static void removeFirstListenerCreatedFromMarkup(EventListenerVector* listenerVector) 163 { 164 bool foundListener = false; 165 166 for (size_t i = 0; i < listenerVector->size(); ++i) { 167 if (!listenerVector->at(i).listener->wasCreatedFromMarkup()) 168 continue; 169 foundListener = true; 170 listenerVector->remove(i); 171 break; 172 } 173 159 return nullptr; 160 } 161 162 static void removeFirstListenerCreatedFromMarkup(EventListenerVector& listenerVector) 163 { 164 bool foundListener = listenerVector.removeFirstMatching([] (const RegisteredEventListener& listener) { 165 return listener.listener->wasCreatedFromMarkup(); 166 }); 174 167 ASSERT_UNUSED(foundListener, foundListener); 175 168 } … … 181 174 for (unsigned i = 0; i < m_entries.size(); ++i) { 182 175 if (m_entries[i].first == eventType) { 183 removeFirstListenerCreatedFromMarkup( m_entries[i].second.get());176 removeFirstListenerCreatedFromMarkup(*m_entries[i].second); 184 177 if (m_entries[i].second->isEmpty()) 185 178 m_entries.remove(i); -
trunk/Source/WebCore/dom/Node.cpp
r179143 r179791 1953 1953 return; 1954 1954 1955 for (size_t i = 0; i < registry->size(); ++i) { 1956 if (registry->at(i).get() == registration) { 1957 registry->remove(i); 1958 return; 1959 } 1960 } 1955 registry->removeFirstMatching([registration] (const std::unique_ptr<MutationObserverRegistration>& current) { 1956 return current.get() == registration; 1957 }); 1961 1958 } 1962 1959 -
trunk/Source/WebCore/html/parser/HTMLTreeBuilder.cpp
r178265 r179791 442 442 { 443 443 Vector<Attribute> attributes = token.attributes(); 444 for (int i = attributes.size() - 1; i >= 0; --i) { 445 const QualifiedName& name = attributes.at(i).name(); 446 if (name.matches(nameAttr) || name.matches(actionAttr) || name.matches(promptAttr)) 447 attributes.remove(i); 448 } 444 attributes.removeAllMatching([] (const Attribute& attribute) { 445 const QualifiedName& name = attribute.name(); 446 return name.matches(nameAttr) || name.matches(actionAttr) || name.matches(promptAttr); 447 }); 449 448 450 449 attributes.append(Attribute(nameAttr, isindexTag.localName())); -
trunk/Source/WebCore/platform/graphics/texmap/TextureMapperAnimation.cpp
r178182 r179791 366 366 void TextureMapperAnimations::remove(const String& name) 367 367 { 368 for (int i = m_animations.size() - 1; i >= 0; --i) { 369 if (m_animations[i].name() == name) 370 m_animations.remove(i); 371 } 368 m_animations.removeAllMatching([&name] (const TextureMapperAnimation& animation) { 369 return animation.name() == name; 370 }); 372 371 } 373 372 374 373 void TextureMapperAnimations::remove(const String& name, AnimatedPropertyID property) 375 374 { 376 for (int i = m_animations.size() - 1; i >= 0; --i) { 377 if (m_animations[i].name() == name && m_animations[i].property() == property) 378 m_animations.remove(i); 379 } 375 m_animations.removeAllMatching([&name, property] (const TextureMapperAnimation& animation) { 376 return animation.name() == name && animation.property() == property; 377 }); 380 378 } 381 379 -
trunk/Source/WebCore/svg/animation/SVGSMILElement.cpp
r179695 r179791 215 215 static inline void clearTimesWithDynamicOrigins(Vector<SMILTimeWithOrigin>& timeList) 216 216 { 217 for (int i = timeList.size() - 1; i >= 0; --i) { 218 if (timeList[i].originIsScript()) 219 timeList.remove(i); 220 } 217 timeList.removeAllMatching([] (const SMILTimeWithOrigin& time) { 218 return time.originIsScript(); 219 }); 221 220 } 222 221 -
trunk/Source/WebKit/win/ChangeLog
r179489 r179791 1 2015-02-07 Chris Dumez <cdumez@apple.com> 2 3 Add Vector::removeFirstMatching() / removeAllMatching() methods taking lambda functions 4 https://bugs.webkit.org/show_bug.cgi?id=141321 5 6 Reviewed by Darin Adler. 7 8 Use new Vector::removeFirstMatching() / removeAllMatching() methods. 9 1 10 2015-02-02 Chris Dumez <cdumez@apple.com> 2 11 -
trunk/Source/WebKit/win/WebNotificationCenter.cpp
r176892 r179791 201 201 ObserverListIterator end = observerList.end(); 202 202 203 int i = 0; 204 for (ObserverListIterator it2 = observerList.begin(); it2 != end; ++it2, ++i) { 205 IUnknown* observedObject = it2->first.get(); 206 IWebNotificationObserver* observer = it2->second.get(); 207 if (observer == anObserver && (!anObject || anObject == observedObject)) { 208 observerList.remove(i); 209 break; 210 } 211 } 203 observerList.removeFirstMatching([anObject, anObserver] (const ObjectObserverPair& pair) { 204 IUnknown* observedObject = pair.first.get(); 205 IWebNotificationObserver* observer = pair.second.get(); 206 return observer == anObserver && (!anObject || anObject == observedObject); 207 }); 212 208 213 209 if (observerList.isEmpty()) -
trunk/Source/WebKit2/ChangeLog
r179786 r179791 1 2015-02-07 Chris Dumez <cdumez@apple.com> 2 3 Add Vector::removeFirstMatching() / removeAllMatching() methods taking lambda functions 4 https://bugs.webkit.org/show_bug.cgi?id=141321 5 6 Reviewed by Darin Adler. 7 8 Use new Vector::removeFirstMatching() / removeAllMatching() methods. 9 1 10 2015-02-07 Tim Horton <timothy_horton@apple.com> 2 11 -
trunk/Source/WebKit2/WebProcess/WebPage/mac/PlatformCALayerRemote.cpp
r179604 r179791 351 351 { 352 352 if (m_animations.remove(key)) { 353 for (size_t i = 0; i < m_properties.addedAnimations.size(); ++i) { 354 if (m_properties.addedAnimations[i].first == key) { 355 m_properties.addedAnimations.remove(i); 356 break; 357 } 358 } 353 m_properties.addedAnimations.removeFirstMatching([&key] (const std::pair<String, PlatformCAAnimationRemote::Properties>& pair) { 354 return pair.first == key; 355 }); 359 356 } 360 357 m_properties.keyPathsOfAnimationsToRemove.add(key); -
trunk/Tools/ChangeLog
r179788 r179791 1 2015-02-07 Chris Dumez <cdumez@apple.com> 2 3 Add Vector::removeFirstMatching() / removeAllMatching() methods taking lambda functions 4 https://bugs.webkit.org/show_bug.cgi?id=141321 5 6 Reviewed by Darin Adler. 7 8 Use new Vector::removeFirstMatching() / removeAllMatching() methods. 9 1 10 2015-02-07 David Kilzer <ddkilzer@apple.com> 2 11 -
trunk/Tools/TestWebKitAPI/Tests/WTF/Vector.cpp
r179599 r179791 464 464 } 465 465 466 TEST(WTF_Vector, RemoveFirstMatching) 467 { 468 Vector<int> v; 469 EXPECT_TRUE(v.isEmpty()); 470 EXPECT_FALSE(v.removeFirstMatching([] (int value) { return value > 0; })); 471 EXPECT_FALSE(v.removeFirstMatching([] (int) { return true; })); 472 EXPECT_FALSE(v.removeFirstMatching([] (int) { return false; })); 473 474 v = {3, 1, 2, 1, 2, 1, 2, 2, 1, 1, 1, 3}; 475 EXPECT_EQ(12U, v.size()); 476 EXPECT_FALSE(v.removeFirstMatching([] (int) { return false; })); 477 EXPECT_EQ(12U, v.size()); 478 EXPECT_FALSE(v.removeFirstMatching([] (int value) { return value < 0; })); 479 EXPECT_EQ(12U, v.size()); 480 EXPECT_TRUE(v.removeFirstMatching([] (int value) { return value < 3; })); 481 EXPECT_EQ(11U, v.size()); 482 EXPECT_TRUE(v == Vector<int>({3, 2, 1, 2, 1, 2, 2, 1, 1, 1, 3})); 483 EXPECT_TRUE(v.removeFirstMatching([] (int value) { return value > 2; })); 484 EXPECT_EQ(10U, v.size()); 485 EXPECT_TRUE(v == Vector<int>({2, 1, 2, 1, 2, 2, 1, 1, 1, 3})); 486 EXPECT_TRUE(v.removeFirstMatching([] (int value) { return value > 2; })); 487 EXPECT_EQ(9U, v.size()); 488 EXPECT_TRUE(v == Vector<int>({2, 1, 2, 1, 2, 2, 1, 1, 1})); 489 } 490 491 TEST(WTF_Vector, RemoveAllMatching) 492 { 493 Vector<int> v; 494 EXPECT_TRUE(v.isEmpty()); 495 EXPECT_FALSE(v.removeAllMatching([] (int value) { return value > 0; })); 496 EXPECT_FALSE(v.removeAllMatching([] (int) { return true; })); 497 EXPECT_FALSE(v.removeAllMatching([] (int) { return false; })); 498 499 v = {3, 1, 2, 1, 2, 1, 2, 2, 1, 1, 1, 3}; 500 EXPECT_EQ(12U, v.size()); 501 EXPECT_EQ(0U, v.removeAllMatching([] (int) { return false; })); 502 EXPECT_EQ(12U, v.size()); 503 EXPECT_EQ(0U, v.removeAllMatching([] (int value) { return value < 0; })); 504 EXPECT_EQ(12U, v.size()); 505 EXPECT_EQ(12U, v.removeAllMatching([] (int value) { return value > 0; })); 506 EXPECT_TRUE(v.isEmpty()); 507 508 v = {3, 1, 2, 1, 2, 1, 3, 2, 2, 1, 1, 1, 3}; 509 EXPECT_EQ(13U, v.size()); 510 EXPECT_EQ(3U, v.removeAllMatching([] (int value) { return value > 2; })); 511 EXPECT_EQ(10U, v.size()); 512 EXPECT_TRUE(v == Vector<int>({1, 2, 1, 2, 1, 2, 2, 1, 1, 1})); 513 EXPECT_EQ(6U, v.removeAllMatching([] (int value) { return value != 2; })); 514 EXPECT_EQ(4U, v.size()); 515 EXPECT_TRUE(v == Vector<int>({2, 2, 2, 2})); 516 EXPECT_EQ(4U, v.removeAllMatching([] (int value) { return value == 2; })); 517 EXPECT_TRUE(v.isEmpty()); 518 } 519 466 520 } // namespace TestWebKitAPI -
trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp
r179409 r179791 110 110 void InjectedBundle::willDestroyPage(WKBundlePageRef page) 111 111 { 112 size_t size = m_pages.size(); 113 for (size_t i = 0; i < size; ++i) { 114 if (m_pages[i]->page() == page) { 115 m_pages.remove(i); 116 break; 117 } 118 } 112 m_pages.removeFirstMatching([page] (const std::unique_ptr<InjectedBundlePage>& current) { 113 return current->page() == page; 114 }); 119 115 } 120 116
Note: See TracChangeset
for help on using the changeset viewer.