Diff
Modified: trunk/Source/_javascript_Core/ChangeLog (179598 => 179599)
--- trunk/Source/_javascript_Core/ChangeLog 2015-02-04 07:37:18 UTC (rev 179598)
+++ trunk/Source/_javascript_Core/ChangeLog 2015-02-04 08:39:20 UTC (rev 179599)
@@ -1,3 +1,16 @@
+2015-02-04 Chris Dumez <[email protected]>
+
+ Add removeFirst(value) / removeAll(value) methods to WTF::Vector
+ https://bugs.webkit.org/show_bug.cgi?id=141192
+
+ Reviewed by Benjamin Poulain.
+
+ Use new Vector::removeFirst(value) / removeAll(value) API to simplify the
+ code a bit.
+
+ * inspector/InspectorValues.cpp:
+ (Inspector::InspectorObjectBase::remove):
+
2015-02-03 Mark Lam <[email protected]>
Workaround a thread library bug where thread destructors may not get called.
Modified: trunk/Source/_javascript_Core/inspector/InspectorValues.cpp (179598 => 179599)
--- trunk/Source/_javascript_Core/inspector/InspectorValues.cpp 2015-02-04 07:37:18 UTC (rev 179598)
+++ trunk/Source/_javascript_Core/inspector/InspectorValues.cpp 2015-02-04 08:39:20 UTC (rev 179599)
@@ -786,12 +786,7 @@
void InspectorObjectBase::remove(const String& name)
{
m_data.remove(name);
- for (size_t i = 0; i < m_order.size(); ++i) {
- if (m_order[i] == name) {
- m_order.remove(i);
- break;
- }
- }
+ m_order.removeFirst(name);
}
void InspectorObjectBase::writeJSON(StringBuilder& output) const
Modified: trunk/Source/WTF/ChangeLog (179598 => 179599)
--- trunk/Source/WTF/ChangeLog 2015-02-04 07:37:18 UTC (rev 179598)
+++ trunk/Source/WTF/ChangeLog 2015-02-04 08:39:20 UTC (rev 179599)
@@ -1,3 +1,21 @@
+2015-02-04 Chris Dumez <[email protected]>
+
+ Add removeFirst(value) / removeAll(value) methods to WTF::Vector
+ https://bugs.webkit.org/show_bug.cgi?id=141192
+
+ Reviewed by Benjamin Poulain.
+
+ Add removeFirst(value) / removeAll(value) convenience methods to
+ WTF::Vector to reduce complexity a bit at call sites.
+
+ I am planning to add overloads for these taking a lambda function for
+ matching in a follow-up patch as well. I have seen quite a few
+ Vector::remove(index) call sites that would benefit from it.
+
+ * wtf/Vector.h:
+ (WTF::OverflowHandler>::removeFirst):
+ (WTF::OverflowHandler>::removeAll):
+
2015-02-02 Dhi Aurrahman <[email protected]>
Optimize matchesLangPseudoClass() of :lang()
Modified: trunk/Source/WTF/wtf/Vector.h (179598 => 179599)
--- trunk/Source/WTF/wtf/Vector.h 2015-02-04 07:37:18 UTC (rev 179598)
+++ trunk/Source/WTF/wtf/Vector.h 2015-02-04 08:39:20 UTC (rev 179599)
@@ -735,6 +735,8 @@
void remove(size_t position);
void remove(size_t position, size_t length);
+ template<typename U> bool removeFirst(const U&);
+ template<typename U> unsigned removeAll(const U&);
void removeLast()
{
@@ -1309,6 +1311,45 @@
}
template<typename T, size_t inlineCapacity, typename OverflowHandler>
+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 false;
+}
+
+template<typename T, size_t inlineCapacity, typename OverflowHandler>
+template<typename U>
+inline unsigned Vector<T, inlineCapacity, OverflowHandler>::removeAll(const U& value)
+{
+ iterator holeBegin = end();
+ iterator holeEnd = end();
+ unsigned matchCount = 0;
+ for (auto it = begin(), itEnd = end(); it != itEnd; ++it) {
+ if (*it == value) {
+ if (holeBegin == end())
+ holeBegin = it;
+ else if (holeEnd != it) {
+ TypeOperations::moveOverlapping(holeEnd, it, holeBegin);
+ holeBegin += it - holeEnd;
+ }
+ holeEnd = it + 1;
+ it->~T();
+ ++matchCount;
+ }
+ }
+ if (holeEnd != end())
+ TypeOperations::moveOverlapping(holeEnd, end(), holeBegin);
+ asanBufferSizeWillChangeTo(m_size - matchCount);
+ m_size -= matchCount;
+ return matchCount;
+}
+
+template<typename T, size_t inlineCapacity, typename OverflowHandler>
inline void Vector<T, inlineCapacity, OverflowHandler>::reverse()
{
for (size_t i = 0; i < m_size / 2; ++i)
Modified: trunk/Source/WebCore/ChangeLog (179598 => 179599)
--- trunk/Source/WebCore/ChangeLog 2015-02-04 07:37:18 UTC (rev 179598)
+++ trunk/Source/WebCore/ChangeLog 2015-02-04 08:39:20 UTC (rev 179599)
@@ -1,3 +1,40 @@
+2015-02-04 Chris Dumez <[email protected]>
+
+ Add removeFirst(value) / removeAll(value) methods to WTF::Vector
+ https://bugs.webkit.org/show_bug.cgi?id=141192
+
+ Reviewed by Benjamin Poulain.
+
+ Use new Vector::removeFirst(value) / removeAll(value) API to simplify the
+ code a bit.
+
+ * css/StyleSheetContents.cpp:
+ (WebCore::StyleSheetContents::unregisterClient):
+ * html/HTMLFormElement.cpp:
+ (WebCore::HTMLFormElement::removeFormElement):
+ (WebCore::HTMLFormElement::removeImgElement):
+ (WebCore::removeFromVector): Deleted.
+ * page/Chrome.cpp:
+ (WebCore::Chrome::unregisterPopupOpeningObserver):
+ * page/PageOverlayController.cpp:
+ (WebCore::PageOverlayController::uninstallPageOverlay):
+ * page/SecurityPolicy.cpp:
+ (WebCore::SecurityPolicy::removeOriginAccessWhitelistEntry):
+ * platform/graphics/GraphicsLayer.cpp:
+ (WebCore::GraphicsLayer::removeFromParent):
+ * platform/graphics/texmap/TextureMapperAnimation.cpp:
+ (WebCore::TextureMapperAnimations::remove):
+ * rendering/RenderSearchField.cpp:
+ (WebCore::RenderSearchField::addSearchResult):
+ * rendering/RenderTable.cpp:
+ (WebCore::RenderTable::removeCaption):
+ * rendering/svg/RenderSVGText.cpp:
+ (WebCore::RenderSVGText::subtreeChildWillBeRemoved):
+ * svg/SVGDocumentExtensions.cpp:
+ (WebCore::SVGDocumentExtensions::removeAllElementReferencesForTarget):
+ * svg/animation/SMILTimeContainer.cpp:
+ (WebCore::SMILTimeContainer::unschedule):
+
2015-02-03 Maciej Stachowiak <[email protected]>
Crash when printing snapshotted plugins
Modified: trunk/Source/WebCore/css/StyleSheetContents.cpp (179598 => 179599)
--- trunk/Source/WebCore/css/StyleSheetContents.cpp 2015-02-04 07:37:18 UTC (rev 179598)
+++ trunk/Source/WebCore/css/StyleSheetContents.cpp 2015-02-04 08:39:20 UTC (rev 179599)
@@ -484,9 +484,8 @@
void StyleSheetContents::unregisterClient(CSSStyleSheet* sheet)
{
- size_t position = m_clients.find(sheet);
- ASSERT(position != notFound);
- m_clients.remove(position);
+ bool removed = m_clients.removeFirst(sheet);
+ ASSERT_UNUSED(removed, removed);
}
void StyleSheetContents::addedToMemoryCache()
Modified: trunk/Source/WebCore/html/HTMLFormElement.cpp (179598 => 179599)
--- trunk/Source/WebCore/html/HTMLFormElement.cpp 2015-02-04 07:37:18 UTC (rev 179598)
+++ trunk/Source/WebCore/html/HTMLFormElement.cpp 2015-02-04 08:39:20 UTC (rev 179599)
@@ -510,16 +510,6 @@
HTMLElement::parseAttribute(name, value);
}
-template<class T, size_t n> static void removeFromVector(Vector<T*, n> & vec, T* item)
-{
- size_t size = vec.size();
- for (size_t i = 0; i != size; ++i)
- if (vec[i] == item) {
- vec.remove(i);
- break;
- }
-}
-
unsigned HTMLFormElement::formElementIndexWithFormAttribute(Element* element, unsigned rangeStart, unsigned rangeEnd)
{
if (m_associatedElements.isEmpty())
@@ -608,18 +598,14 @@
void HTMLFormElement::removeFormElement(FormAssociatedElement* e)
{
- unsigned index;
- for (index = 0; index < m_associatedElements.size(); ++index) {
- if (m_associatedElements[index] == e)
- break;
- }
+ unsigned index = m_associatedElements.find(e);
ASSERT_WITH_SECURITY_IMPLICATION(index < m_associatedElements.size());
if (index < m_associatedElementsBeforeIndex)
--m_associatedElementsBeforeIndex;
if (index < m_associatedElementsAfterIndex)
--m_associatedElementsAfterIndex;
removeFromPastNamesMap(e);
- removeFromVector(m_associatedElements, e);
+ m_associatedElements.remove(index);
}
void HTMLFormElement::registerInvalidAssociatedFormControl(const HTMLFormControlElement& formControlElement)
@@ -653,9 +639,9 @@
void HTMLFormElement::removeImgElement(HTMLImageElement* e)
{
- ASSERT(m_imageElements.find(e) != notFound);
removeFromPastNamesMap(e);
- removeFromVector(m_imageElements, e);
+ bool removed = m_imageElements.removeFirst(e);
+ ASSERT_UNUSED(removed, removed);
}
RefPtr<HTMLCollection> HTMLFormElement::elements()
Modified: trunk/Source/WebCore/page/Chrome.cpp (179598 => 179599)
--- trunk/Source/WebCore/page/Chrome.cpp 2015-02-04 07:37:18 UTC (rev 179598)
+++ trunk/Source/WebCore/page/Chrome.cpp 2015-02-04 08:39:20 UTC (rev 179599)
@@ -637,9 +637,8 @@
void Chrome::unregisterPopupOpeningObserver(PopupOpeningObserver* observer)
{
- size_t index = m_popupOpeningObservers.find(observer);
- ASSERT(index != notFound);
- m_popupOpeningObservers.remove(index);
+ bool removed = m_popupOpeningObservers.removeFirst(observer);
+ ASSERT_UNUSED(removed, removed);
}
void Chrome::notifyPopupOpeningObservers() const
Modified: trunk/Source/WebCore/page/PageOverlayController.cpp (179598 => 179599)
--- trunk/Source/WebCore/page/PageOverlayController.cpp 2015-02-04 07:37:18 UTC (rev 179598)
+++ trunk/Source/WebCore/page/PageOverlayController.cpp 2015-02-04 08:39:20 UTC (rev 179599)
@@ -151,9 +151,8 @@
m_overlayGraphicsLayers.take(overlay)->removeFromParent();
- size_t overlayIndex = m_pageOverlays.find(overlay);
- ASSERT(overlayIndex != notFound);
- m_pageOverlays.remove(overlayIndex);
+ bool removed = m_pageOverlays.removeFirst(overlay);
+ ASSERT_UNUSED(removed, removed);
updateForceSynchronousScrollLayerPositionUpdates();
}
Modified: trunk/Source/WebCore/page/SecurityPolicy.cpp (179598 => 179599)
--- trunk/Source/WebCore/page/SecurityPolicy.cpp 2015-02-04 07:37:18 UTC (rev 179598)
+++ trunk/Source/WebCore/page/SecurityPolicy.cpp 2015-02-04 08:39:20 UTC (rev 179599)
@@ -154,14 +154,12 @@
if (it == map.end())
return;
- OriginAccessWhiteList* list = it->value.get();
- size_t index = list->find(OriginAccessEntry(destinationProtocol, destinationDomain, allowDestinationSubdomains ? OriginAccessEntry::AllowSubdomains : OriginAccessEntry::DisallowSubdomains));
- if (index == notFound)
+ OriginAccessWhiteList& list = *it->value;
+ OriginAccessEntry originAccessEntry(destinationProtocol, destinationDomain, allowDestinationSubdomains ? OriginAccessEntry::AllowSubdomains : OriginAccessEntry::DisallowSubdomains);
+ if (!list.removeFirst(originAccessEntry))
return;
- list->remove(index);
-
- if (list->isEmpty())
+ if (list.isEmpty())
map.remove(it);
}
Modified: trunk/Source/WebCore/platform/graphics/GraphicsLayer.cpp (179598 => 179599)
--- trunk/Source/WebCore/platform/graphics/GraphicsLayer.cpp 2015-02-04 07:37:18 UTC (rev 179598)
+++ trunk/Source/WebCore/platform/graphics/GraphicsLayer.cpp 2015-02-04 08:39:20 UTC (rev 179599)
@@ -253,14 +253,7 @@
void GraphicsLayer::removeFromParent()
{
if (m_parent) {
- unsigned i;
- for (i = 0; i < m_parent->m_children.size(); i++) {
- if (this == m_parent->m_children[i]) {
- m_parent->m_children.remove(i);
- break;
- }
- }
-
+ m_parent->m_children.removeFirst(this);
setParent(nullptr);
}
}
Modified: trunk/Source/WebCore/rendering/RenderSearchField.cpp (179598 => 179599)
--- trunk/Source/WebCore/rendering/RenderSearchField.cpp 2015-02-04 07:37:18 UTC (rev 179598)
+++ trunk/Source/WebCore/rendering/RenderSearchField.cpp 2015-02-04 08:39:20 UTC (rev 179599)
@@ -88,12 +88,7 @@
if (frame().page()->usesEphemeralSession())
return;
- int size = static_cast<int>(m_recentSearches.size());
- for (int i = size - 1; i >= 0; --i) {
- if (m_recentSearches[i] == value)
- m_recentSearches.remove(i);
- }
-
+ m_recentSearches.removeAll(value);
m_recentSearches.insert(0, value);
while (static_cast<int>(m_recentSearches.size()) > inputElement().maxResults())
m_recentSearches.removeLast();
Modified: trunk/Source/WebCore/rendering/RenderTable.cpp (179598 => 179599)
--- trunk/Source/WebCore/rendering/RenderTable.cpp 2015-02-04 07:37:18 UTC (rev 179598)
+++ trunk/Source/WebCore/rendering/RenderTable.cpp 2015-02-04 08:39:20 UTC (rev 179599)
@@ -230,12 +230,8 @@
void RenderTable::removeCaption(const RenderTableCaption* oldCaption)
{
- size_t index = m_captions.find(oldCaption);
- ASSERT(index != notFound);
- if (index == notFound)
- return;
-
- m_captions.remove(index);
+ bool removed = m_captions.removeFirst(oldCaption);
+ ASSERT_UNUSED(removed, removed);
}
void RenderTable::invalidateCachedColumns()
Modified: trunk/Source/WebCore/rendering/svg/RenderSVGText.cpp (179598 => 179599)
--- trunk/Source/WebCore/rendering/svg/RenderSVGText.cpp 2015-02-04 07:37:18 UTC (rev 179598)
+++ trunk/Source/WebCore/rendering/svg/RenderSVGText.cpp 2015-02-04 08:39:20 UTC (rev 179599)
@@ -262,9 +262,8 @@
if (next)
affectedAttributes.append(next);
- size_t position = m_layoutAttributes.find(text.layoutAttributes());
- ASSERT(position != notFound);
- m_layoutAttributes.remove(position);
+ bool removed = m_layoutAttributes.removeFirst(text.layoutAttributes());
+ ASSERT_UNUSED(removed, removed);
}
void RenderSVGText::subtreeChildWasRemoved(const Vector<SVGTextLayoutAttributes*, 2>& affectedAttributes)
Modified: trunk/Source/WebCore/svg/SVGDocumentExtensions.cpp (179598 => 179599)
--- trunk/Source/WebCore/svg/SVGDocumentExtensions.cpp 2015-02-04 07:37:18 UTC (rev 179598)
+++ trunk/Source/WebCore/svg/SVGDocumentExtensions.cpp 2015-02-04 08:39:20 UTC (rev 179599)
@@ -379,10 +379,7 @@
void SVGDocumentExtensions::removeAllElementReferencesForTarget(SVGElement* referencedElement)
{
m_elementDependencies.remove(referencedElement);
-
- size_t position = m_rebuildElements.find(referencedElement);
- if (position != notFound)
- m_rebuildElements.remove(position);
+ m_rebuildElements.removeFirst(referencedElement);
}
#if ENABLE(SVG_FONTS)
Modified: trunk/Source/WebCore/svg/animation/SMILTimeContainer.cpp (179598 => 179599)
--- trunk/Source/WebCore/svg/animation/SMILTimeContainer.cpp 2015-02-04 07:37:18 UTC (rev 179598)
+++ trunk/Source/WebCore/svg/animation/SMILTimeContainer.cpp 2015-02-04 08:39:20 UTC (rev 179599)
@@ -92,9 +92,8 @@
ElementAttributePair key(target, attributeName);
AnimationsVector* scheduled = m_scheduledAnimations.get(key);
ASSERT(scheduled);
- size_t idx = scheduled->find(animation);
- ASSERT(idx != notFound);
- scheduled->remove(idx);
+ bool removed = scheduled->removeFirst(animation);
+ ASSERT_UNUSED(removed, removed);
}
void SMILTimeContainer::notifyIntervalsChanged()
Modified: trunk/Source/WebKit2/ChangeLog (179598 => 179599)
--- trunk/Source/WebKit2/ChangeLog 2015-02-04 07:37:18 UTC (rev 179598)
+++ trunk/Source/WebKit2/ChangeLog 2015-02-04 08:39:20 UTC (rev 179599)
@@ -1,3 +1,23 @@
+2015-02-04 Chris Dumez <[email protected]>
+
+ Add removeFirst(value) / removeAll(value) methods to WTF::Vector
+ https://bugs.webkit.org/show_bug.cgi?id=141192
+
+ Reviewed by Benjamin Poulain.
+
+ Use new Vector::removeFirst(value) / removeAll(value) API to simplify the
+ code a bit.
+
+ * UIProcess/Network/CustomProtocols/soup/WebSoupCustomProtocolRequestManager.cpp:
+ (WebKit::WebSoupCustomProtocolRequestManager::unregisterSchemeForCustomProtocol):
+ * UIProcess/PageLoadState.cpp:
+ (WebKit::PageLoadState::removeObserver):
+ * UIProcess/WebProcessPool.cpp:
+ (WebKit::WebProcessPool::~WebProcessPool):
+ (WebKit::WebProcessPool::disconnectProcess):
+ * WebProcess/InjectedBundle/API/efl/ewk_extension.cpp:
+ (EwkExtension::remove):
+
2015-02-03 Chris Dumez <[email protected]>
Unreviewed attempt to fix GTK/EFL build after r179588.
Modified: trunk/Source/WebKit2/UIProcess/Network/CustomProtocols/soup/WebSoupCustomProtocolRequestManager.cpp (179598 => 179599)
--- trunk/Source/WebKit2/UIProcess/Network/CustomProtocols/soup/WebSoupCustomProtocolRequestManager.cpp 2015-02-04 07:37:18 UTC (rev 179598)
+++ trunk/Source/WebKit2/UIProcess/Network/CustomProtocols/soup/WebSoupCustomProtocolRequestManager.cpp 2015-02-04 08:39:20 UTC (rev 179599)
@@ -96,8 +96,8 @@
processPool()->unregisterSchemeForCustomProtocol(scheme);
- ASSERT(m_registeredSchemes.contains(scheme));
- m_registeredSchemes.remove(m_registeredSchemes.find(scheme));
+ bool removed = m_registeredSchemes.removeFirst(scheme);
+ ASSERT_UNUSED(removed, removed);
}
void WebSoupCustomProtocolRequestManager::startLoading(uint64_t customProtocolID, const WebCore::ResourceRequest& request)
Modified: trunk/Source/WebKit2/UIProcess/PageLoadState.cpp (179598 => 179599)
--- trunk/Source/WebKit2/UIProcess/PageLoadState.cpp 2015-02-04 07:37:18 UTC (rev 179598)
+++ trunk/Source/WebKit2/UIProcess/PageLoadState.cpp 2015-02-04 08:39:20 UTC (rev 179599)
@@ -74,10 +74,8 @@
void PageLoadState::removeObserver(Observer& observer)
{
- ASSERT(m_observers.contains(&observer));
-
- size_t index = m_observers.find(&observer);
- m_observers.remove(index);
+ bool removed = m_observers.removeFirst(&observer);
+ ASSERT_UNUSED(removed, removed);
}
void PageLoadState::endTransaction()
Modified: trunk/Source/WebKit2/UIProcess/WebProcessPool.cpp (179598 => 179599)
--- trunk/Source/WebKit2/UIProcess/WebProcessPool.cpp 2015-02-04 07:37:18 UTC (rev 179598)
+++ trunk/Source/WebKit2/UIProcess/WebProcessPool.cpp 2015-02-04 08:39:20 UTC (rev 179599)
@@ -237,8 +237,8 @@
WebProcessPool::~WebProcessPool()
{
- ASSERT(processPools().find(this) != notFound);
- processPools().remove(processPools().find(this));
+ bool removed = processPools().removeFirst(this);
+ ASSERT_UNUSED(removed, removed);
removeLanguageChangeObserver(this);
@@ -805,7 +805,7 @@
static_cast<WebContextSupplement*>(supplement<WebGeolocationManagerProxy>())->processDidClose(process);
- m_processes.remove(m_processes.find(process));
+ m_processes.removeFirst(process);
return;
}
@@ -819,8 +819,8 @@
// if it were invoked from Vector::remove(). RefPtr delays destruction until it's safe.
RefPtr<WebProcessProxy> protect(process);
if (m_processWithPageCache == process)
- m_processWithPageCache = 0;
- m_processes.remove(m_processes.find(process));
+ m_processWithPageCache = nullptr;
+ m_processes.removeFirst(process);
}
WebProcessProxy& WebProcessPool::createNewWebProcessRespectingProcessCountLimit()
Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/API/efl/ewk_extension.cpp (179598 => 179599)
--- trunk/Source/WebKit2/WebProcess/InjectedBundle/API/efl/ewk_extension.cpp 2015-02-04 07:37:18 UTC (rev 179598)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/API/efl/ewk_extension.cpp 2015-02-04 08:39:20 UTC (rev 179599)
@@ -37,7 +37,7 @@
void EwkExtension::remove(Ewk_Extension_Client* client)
{
- m_clients.remove(m_clients.find(client));
+ m_clients.removeFirst(client);
}
Eina_Bool ewk_extension_client_add(Ewk_Extension* extension, Ewk_Extension_Client* client)
Modified: trunk/Tools/ChangeLog (179598 => 179599)
--- trunk/Tools/ChangeLog 2015-02-04 07:37:18 UTC (rev 179598)
+++ trunk/Tools/ChangeLog 2015-02-04 08:39:20 UTC (rev 179599)
@@ -1,3 +1,16 @@
+2015-02-04 Chris Dumez <[email protected]>
+
+ Add removeFirst(value) / removeAll(value) methods to WTF::Vector
+ https://bugs.webkit.org/show_bug.cgi?id=141192
+
+ Reviewed by Benjamin Poulain.
+
+ Add API tests for Vector::removeFirst(value) and
+ Vector::removeAll(value).
+
+ * TestWebKitAPI/Tests/WTF/Vector.cpp:
+ (TestWebKitAPI::TEST):
+
2015-02-03 Tim Horton <[email protected]>
Add WKPageNavigationClient as C SPI around API::NavigationClient, and adopt in WKTR
Modified: trunk/Tools/TestWebKitAPI/Tests/WTF/Vector.cpp (179598 => 179599)
--- trunk/Tools/TestWebKitAPI/Tests/WTF/Vector.cpp 2015-02-04 07:37:18 UTC (rev 179598)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/Vector.cpp 2015-02-04 08:39:20 UTC (rev 179599)
@@ -27,6 +27,7 @@
#include "MoveOnly.h"
#include <wtf/Vector.h>
+#include <wtf/text/CString.h>
namespace TestWebKitAPI {
@@ -323,4 +324,143 @@
EXPECT_EQ(0U, b.size());
}
+TEST(WTF_Vector, RemoveFirst)
+{
+ Vector<int> v;
+ EXPECT_TRUE(v.isEmpty());
+ EXPECT_FALSE(v.removeFirst(1));
+ EXPECT_FALSE(v.removeFirst(-1));
+ EXPECT_TRUE(v.isEmpty());
+
+ v.fill(2, 10);
+ EXPECT_EQ(10U, v.size());
+ EXPECT_FALSE(v.removeFirst(1));
+ EXPECT_EQ(10U, v.size());
+ v.clear();
+
+ v.fill(1, 10);
+ EXPECT_EQ(10U, v.size());
+ EXPECT_TRUE(v.removeFirst(1));
+ EXPECT_TRUE(v == Vector<int>({1, 1, 1, 1, 1, 1, 1, 1, 1}));
+ EXPECT_EQ(9U, v.size());
+ EXPECT_FALSE(v.removeFirst(2));
+ EXPECT_EQ(9U, v.size());
+ EXPECT_TRUE(v == Vector<int>({1, 1, 1, 1, 1, 1, 1, 1, 1}));
+
+ unsigned removed = 0;
+ while (v.removeFirst(1))
+ ++removed;
+ EXPECT_EQ(9U, removed);
+ EXPECT_TRUE(v.isEmpty());
+
+ v.resize(1);
+ EXPECT_EQ(1U, v.size());
+ EXPECT_TRUE(v.removeFirst(1));
+ EXPECT_EQ(0U, v.size());
+ EXPECT_TRUE(v.isEmpty());
+}
+
+TEST(WTF_Vector, RemoveAll)
+{
+ // Using a memcpy-able type.
+ static_assert(VectorTraits<int>::canMoveWithMemcpy, "Should use a memcpy-able type");
+ Vector<int> v;
+ EXPECT_TRUE(v.isEmpty());
+ EXPECT_FALSE(v.removeAll(1));
+ EXPECT_FALSE(v.removeAll(-1));
+ EXPECT_TRUE(v.isEmpty());
+
+ v.fill(1, 10);
+ EXPECT_EQ(10U, v.size());
+ EXPECT_EQ(10U, v.removeAll(1));
+ EXPECT_TRUE(v.isEmpty());
+
+ v.fill(2, 10);
+ EXPECT_EQ(10U, v.size());
+ EXPECT_EQ(0U, v.removeAll(1));
+ EXPECT_EQ(10U, v.size());
+
+ v = {1, 2, 1, 2, 1, 2, 2, 1, 1, 1};
+ EXPECT_EQ(10U, v.size());
+ EXPECT_EQ(6U, v.removeAll(1));
+ EXPECT_EQ(4U, v.size());
+ EXPECT_TRUE(v == Vector<int>({2, 2, 2, 2}));
+ EXPECT_TRUE(v.find(1) == notFound);
+ EXPECT_EQ(4U, v.removeAll(2));
+ EXPECT_TRUE(v.isEmpty());
+
+ v = {3, 1, 2, 1, 2, 1, 2, 2, 1, 1, 1, 3};
+ EXPECT_EQ(12U, v.size());
+ EXPECT_EQ(6U, v.removeAll(1));
+ EXPECT_EQ(6U, v.size());
+ EXPECT_TRUE(v.find(1) == notFound);
+ EXPECT_TRUE(v == Vector<int>({3, 2, 2, 2, 2, 3}));
+
+ EXPECT_EQ(4U, v.removeAll(2));
+ EXPECT_EQ(2U, v.size());
+ EXPECT_TRUE(v.find(2) == notFound);
+ EXPECT_TRUE(v == Vector<int>({3, 3}));
+
+ EXPECT_EQ(2U, v.removeAll(3));
+ EXPECT_TRUE(v.isEmpty());
+
+ v = {1, 1, 1, 3, 2, 4, 2, 2, 2, 4, 4, 3};
+ EXPECT_EQ(12U, v.size());
+ EXPECT_EQ(3U, v.removeAll(1));
+ EXPECT_EQ(9U, v.size());
+ EXPECT_TRUE(v.find(1) == notFound);
+ EXPECT_TRUE(v == Vector<int>({3, 2, 4, 2, 2, 2, 4, 4, 3}));
+
+ // Using a non memcpy-able type.
+ static_assert(!VectorTraits<CString>::canMoveWithMemcpy, "Should use a non memcpy-able type");
+ Vector<CString> vExpected;
+ Vector<CString> v2;
+ EXPECT_TRUE(v2.isEmpty());
+ EXPECT_FALSE(v2.removeAll("1"));
+ EXPECT_TRUE(v2.isEmpty());
+
+ v2.fill("1", 10);
+ EXPECT_EQ(10U, v2.size());
+ EXPECT_EQ(10U, v2.removeAll("1"));
+ EXPECT_TRUE(v2.isEmpty());
+
+ v2.fill("2", 10);
+ EXPECT_EQ(10U, v2.size());
+ EXPECT_EQ(0U, v2.removeAll("1"));
+ EXPECT_EQ(10U, v2.size());
+
+ v2 = {"1", "2", "1", "2", "1", "2", "2", "1", "1", "1"};
+ EXPECT_EQ(10U, v2.size());
+ EXPECT_EQ(6U, v2.removeAll("1"));
+ EXPECT_EQ(4U, v2.size());
+ EXPECT_TRUE(v2.find("1") == notFound);
+ EXPECT_EQ(4U, v2.removeAll("2"));
+ EXPECT_TRUE(v2.isEmpty());
+
+ v2 = {"3", "1", "2", "1", "2", "1", "2", "2", "1", "1", "1", "3"};
+ EXPECT_EQ(12U, v2.size());
+ EXPECT_EQ(6U, v2.removeAll("1"));
+ EXPECT_EQ(6U, v2.size());
+ EXPECT_TRUE(v2.find("1") == notFound);
+ vExpected = {"3", "2", "2", "2", "2", "3"};
+ EXPECT_TRUE(v2 == vExpected);
+
+ EXPECT_EQ(4U, v2.removeAll("2"));
+ EXPECT_EQ(2U, v2.size());
+ EXPECT_TRUE(v2.find("2") == notFound);
+ vExpected = {"3", "3"};
+ EXPECT_TRUE(v2 == vExpected);
+
+ EXPECT_EQ(2U, v2.removeAll("3"));
+ EXPECT_TRUE(v2.isEmpty());
+
+ v2 = {"1", "1", "1", "3", "2", "4", "2", "2", "2", "4", "4", "3"};
+ EXPECT_EQ(12U, v2.size());
+ EXPECT_EQ(3U, v2.removeAll("1"));
+ EXPECT_EQ(9U, v2.size());
+ EXPECT_TRUE(v2.find("1") == notFound);
+ vExpected = {"3", "2", "4", "2", "2", "2", "4", "4", "3"};
+ EXPECT_TRUE(v2 == vExpected);
+}
+
} // namespace TestWebKitAPI