Skip to content
Permalink
Browse files
Remove out-parameter variants of copyToVector
https://bugs.webkit.org/show_bug.cgi?id=178155

Reviewed by Tim Horton.

Source/JavaScriptCore:

* inspector/ScriptDebugServer.cpp:
(Inspector::ScriptDebugServer::dispatchBreakpointActionLog):
(Inspector::ScriptDebugServer::dispatchBreakpointActionSound):
(Inspector::ScriptDebugServer::dispatchBreakpointActionProbe):
(Inspector::ScriptDebugServer::dispatchDidParseSource):
(Inspector::ScriptDebugServer::dispatchFailedToParseSource):
(Inspector::ScriptDebugServer::dispatchFunctionToListeners):

    Replace out-parameter based copyToVector, with one that returns a Vector.

Source/WebCore:

* Modules/geolocation/Geolocation.cpp:
(WebCore::Geolocation::stopTimersForOneShots):
(WebCore::Geolocation::cancelAllRequests):
(WebCore::Geolocation::handleError):
(WebCore::Geolocation::makeSuccessCallbacks):
* Modules/indexeddb/IDBDatabase.cpp:
(WebCore::IDBDatabase::transaction):
* Modules/indexeddb/IDBGetAllResult.cpp:
(WebCore::IDBGetAllResult::allBlobFilePaths const):
* Modules/indexeddb/server/MemoryIndex.cpp:
(WebCore::IDBServer::MemoryIndex::notifyCursorsOfValueChange):
(WebCore::IDBServer::MemoryIndex::notifyCursorsOfAllRecordsChanged):
* css/CSSFontSelector.cpp:
(WebCore::CSSFontSelector::dispatchInvalidationCallbacks):
* dom/Document.cpp:
(WebCore::Document::moveNodeIteratorsToNewDocument):
(WebCore::Document::resume):
(WebCore::Document::didAssociateFormControlsTimerFired):
* dom/IdTargetObserverRegistry.cpp:
(WebCore::IdTargetObserverRegistry::notifyObserversInternal):
* dom/MutationObserver.cpp:
(WebCore::MutationObserver::notifyMutationObservers):
* dom/Node.cpp:
(WebCore::Document::invalidateNodeListAndCollectionCaches):
* dom/RadioButtonGroups.cpp:
* dom/ScriptExecutionContext.cpp:
(WebCore::ScriptExecutionContext::dispatchMessagePortEvents):
(WebCore::ScriptExecutionContext::stopActiveDOMObjects):
* loader/appcache/ApplicationCacheGroup.cpp:
(WebCore::ApplicationCacheGroup::checkIfLoadIsComplete):
(WebCore::ApplicationCacheGroup::deliverDelayedMainResources):
* loader/cache/MemoryCache.cpp:
(WebCore::MemoryCache::forEachResource):
(WebCore::MemoryCache::pruneDeadResourcesToSize):
* page/DOMWindow.cpp:
(WebCore::DOMWindow::willDestroyCachedFrame):
(WebCore::DOMWindow::willDestroyDocumentInFrame):
(WebCore::DOMWindow::willDetachDocumentFromFrame):
(WebCore::DOMWindow::disconnectDOMWindowProperties):
(WebCore::DOMWindow::reconnectDOMWindowProperties):
* page/FrameView.cpp:
(WebCore::collectAndProtectWidgets):
* page/MemoryRelease.cpp:
(WebCore::releaseCriticalMemory):
* page/Performance.cpp:
(WebCore::Performance::queueEntry):
* platform/cocoa/PasteboardCocoa.mm:
(WebCore::Pasteboard::typesForLegacyUnsafeBindings):
* platform/graphics/cocoa/FontCacheCoreText.cpp:
(WebCore::FontCache::systemFontFamilies):
* platform/ios/PlatformPasteboardIOS.mm:
(WebCore::PlatformPasteboard::typesSafeForDOMToReadAndWrite const):
* platform/ios/WebCoreMotionManager.mm:
(-[WebCoreMotionManager sendAccelerometerData:]):
(-[WebCoreMotionManager sendMotionData:withHeading:]):
* platform/mac/PlatformPasteboardMac.mm:
(WebCore::PlatformPasteboard::typesSafeForDOMToReadAndWrite const):
* platform/network/cocoa/WebCoreNSURLSession.mm:
(-[WebCoreNSURLSession invalidateAndCancel]):
* rendering/RenderBlock.cpp:
(WebCore::RenderBlock::endAndCommitUpdateScrollInfoAfterLayoutTransaction):
* rendering/RenderBlockLineLayout.cpp:
(WebCore::setLogicalWidthForTextRun):
* rendering/RenderDeprecatedFlexibleBox.cpp:
(WebCore::FlexBoxIterator::next):
* rendering/RenderTableSection.cpp:
(WebCore::RenderTableSection::paintObject):

    Replace out-parameter based copyToVector, with one that returns a Vector.

Source/WebKit:

* Shared/API/Cocoa/_WKRemoteObjectInterface.mm:
(-[_WKRemoteObjectInterface debugDescription]):
* Shared/RemoteLayerTree/RemoteScrollingCoordinatorTransaction.cpp:
(WebKit::dump):
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::resetState):
* UIProcess/WebProcessPool.cpp:
(WebKit::WebProcessPool::createNewWebProcess):
* UIProcess/WebsiteData/Cocoa/WebsiteDataStoreCocoa.mm:
(WebKit::WebsiteDataStore::parameters):
* UIProcess/WebsiteData/WebsiteDataStore.cpp:
(WebKit::WebsiteDataStore::pendingCookies const):
* UIProcess/ios/ProcessAssertionIOS.mm:
(-[WKProcessAssertionBackgroundTaskManager _notifyClientsOfImminentSuspension]):
* WebProcess/Cookies/WebCookieManager.cpp:
(WebKit::WebCookieManager::getHostnamesWithCookies):
* WebProcess/Geolocation/WebGeolocationManager.cpp:
(WebKit::WebGeolocationManager::didChangePosition):
(WebKit::WebGeolocationManager::didFailToDeterminePosition):
* WebProcess/Network/WebLoaderStrategy.cpp:
(WebKit::WebLoaderStrategy::internallyFailedLoadTimerFired):

    Replace out-parameter based copyToVector, with one that returns a Vector.

Source/WebKitLegacy/ios:

* Misc/WebGeolocationProviderIOS.mm:
(-[WebGeolocationProviderIOS _handlePendingInitialPosition:]):
(-[WebGeolocationProviderIOS positionChanged:]):
(-[WebGeolocationProviderIOS errorOccurred:]):
(-[WebGeolocationProviderIOS resetGeolocation]):

    Replace out-parameter based copyToVector, with one that returns a Vector.

Source/WebKitLegacy/mac:

* Plugins/WebNetscapePluginView.mm:
(-[WebNetscapePluginView destroyPlugin]):
* WebView/WebHTMLRepresentation.mm:
(newArrayWithStrings):

    Replace out-parameter based copyToVector, with one that returns a Vector.

Source/WTF:

* wtf/HashMap.h:
(WTF::copyToVector): Deleted.
* wtf/HashSet.h:
(WTF::copyToVector): Deleted.

    Remove copyToVector.

* wtf/Vector.h:
(WTF::copyToVectorSpecialization):

    Add another version of copyToVector, called copyToVectorSpecialization, that allows
    you to specify the entire specialization for the Vector you want to copy to. This
    can be useful if you want your resulting Vector to have an inline capacity.

Tools:

* DumpRenderTree/JavaScriptThreading.cpp:
(stopJavaScriptThreads):


Canonical link: https://commits.webkit.org/194462@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@223238 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
weinig committed Oct 12, 2017
1 parent ae8c455 commit 806cb3b040a8e2a4b5a4e55bcb96f597f4d995e3
Showing 54 changed files with 293 additions and 237 deletions.
@@ -1,3 +1,20 @@
2017-10-11 Sam Weinig <sam@webkit.org>

Remove out-parameter variants of copyToVector
https://bugs.webkit.org/show_bug.cgi?id=178155

Reviewed by Tim Horton.

* inspector/ScriptDebugServer.cpp:
(Inspector::ScriptDebugServer::dispatchBreakpointActionLog):
(Inspector::ScriptDebugServer::dispatchBreakpointActionSound):
(Inspector::ScriptDebugServer::dispatchBreakpointActionProbe):
(Inspector::ScriptDebugServer::dispatchDidParseSource):
(Inspector::ScriptDebugServer::dispatchFailedToParseSource):
(Inspector::ScriptDebugServer::dispatchFunctionToListeners):

Replace out-parameter based copyToVector, with one that returns a Vector.

2017-10-12 Yusuke Suzuki <utatane.tea@gmail.com>

Support integrity="" on module scripts
@@ -145,9 +145,7 @@ void ScriptDebugServer::dispatchBreakpointActionLog(ExecState* exec, const Strin

SetForScope<bool> change(m_callingListeners, true);

Vector<ScriptDebugListener*> listenersCopy;
copyToVector(m_listeners, listenersCopy);
for (auto* listener : listenersCopy)
for (auto* listener : copyToVector(m_listeners))
listener->breakpointActionLog(*exec, message);
}

@@ -161,9 +159,7 @@ void ScriptDebugServer::dispatchBreakpointActionSound(ExecState*, int breakpoint

SetForScope<bool> change(m_callingListeners, true);

Vector<ScriptDebugListener*> listenersCopy;
copyToVector(m_listeners, listenersCopy);
for (auto* listener : listenersCopy)
for (auto* listener : copyToVector(m_listeners))
listener->breakpointActionSound(breakpointActionIdentifier);
}

@@ -179,9 +175,7 @@ void ScriptDebugServer::dispatchBreakpointActionProbe(ExecState* exec, const Scr

unsigned sampleId = m_nextProbeSampleId++;

Vector<ScriptDebugListener*> listenersCopy;
copyToVector(m_listeners, listenersCopy);
for (auto* listener : listenersCopy)
for (auto* listener : copyToVector(m_listeners))
listener->breakpointActionProbe(*exec, action, m_currentProbeBatchId, sampleId, sampleValue);
}

@@ -221,10 +215,8 @@ void ScriptDebugServer::dispatchDidParseSource(const ListenerSet& listeners, Sou
else
script.endColumn = sourceLength - lastLineStart;

Vector<ScriptDebugListener*> copy;
copyToVector(listeners, copy);
for (size_t i = 0; i < copy.size(); ++i)
copy[i]->didParseSource(sourceID, script);
for (auto* listener : copyToVector(listeners))
listener->didParseSource(sourceID, script);
}

void ScriptDebugServer::dispatchFailedToParseSource(const ListenerSet& listeners, SourceProvider* sourceProvider, int errorLine, const String& errorMessage)
@@ -233,10 +225,8 @@ void ScriptDebugServer::dispatchFailedToParseSource(const ListenerSet& listeners
String data = sourceProvider->source().toString();
int firstLine = sourceProvider->startPosition().m_line.oneBasedInt();

Vector<ScriptDebugListener*> copy;
copyToVector(listeners, copy);
for (size_t i = 0; i < copy.size(); ++i)
copy[i]->failedToParseSource(url, data, firstLine, errorLine, errorMessage);
for (auto* listener : copyToVector(listeners))
listener->failedToParseSource(url, data, firstLine, errorLine, errorMessage);
}

void ScriptDebugServer::sourceParsed(ExecState* exec, SourceProvider* sourceProvider, int errorLine, const String& errorMessage)
@@ -271,10 +261,8 @@ void ScriptDebugServer::dispatchFunctionToListeners(JavaScriptExecutionCallback

void ScriptDebugServer::dispatchFunctionToListeners(const ListenerSet& listeners, JavaScriptExecutionCallback callback)
{
Vector<ScriptDebugListener*> copy;
copyToVector(listeners, copy);
for (size_t i = 0; i < copy.size(); ++i)
(this->*callback)(copy[i]);
for (auto* listener : copyToVector(listeners))
(this->*callback)(listener);
}

void ScriptDebugServer::notifyDoneProcessingDebuggerEvents()
@@ -1,3 +1,24 @@
2017-10-11 Sam Weinig <sam@webkit.org>

Remove out-parameter variants of copyToVector
https://bugs.webkit.org/show_bug.cgi?id=178155

Reviewed by Tim Horton.

* wtf/HashMap.h:
(WTF::copyToVector): Deleted.
* wtf/HashSet.h:
(WTF::copyToVector): Deleted.

Remove copyToVector.

* wtf/Vector.h:
(WTF::copyToVectorSpecialization):

Add another version of copyToVector, called copyToVectorSpecialization, that allows
you to specify the entire specialization for the Vector you want to copy to. This
can be useful if you want your resulting Vector to have an inline capacity.

2017-10-12 Sam Weinig <sam@webkit.org>

It should be possible to iterate just the values (and not the counts) of a HashCountedSet
@@ -576,19 +576,6 @@ inline bool operator!=(const HashMap<T, U, V, W, X>& a, const HashMap<T, U, V, W
return !(a == b);
}

template<typename T, typename U, typename V, typename W, typename X, typename Y>
inline void copyToVector(const HashMap<T, U, V, W, X>& collection, Y& vector)
{
typedef typename HashMap<T, U, V, W, X>::const_iterator iterator;

vector.resize(collection.size());

iterator it = collection.begin();
iterator end = collection.end();
for (unsigned i = 0; it != end; ++it, ++i)
vector[i] = { (*it).key, (*it).value };
}

} // namespace WTF

using WTF::HashMap;
@@ -355,13 +355,6 @@ namespace WTF {
return true;
}

template<typename C, typename W>
inline void copyToVector(const C& collection, W& vector)
{
vector.resize(collection.size());
std::copy(collection.begin(), collection.end(), vector.begin());
}

template<typename T, typename U, typename V>
template<typename OtherCollection>
inline bool HashSet<T, U, V>::operator==(const OtherCollection& otherCollection) const
@@ -1634,6 +1634,17 @@ Vector<typename Mapper<MapFunction, SourceType>::DestinationItemType> map(Source
return Mapper<MapFunction, SourceType>::map(std::forward<SourceType>(source), std::forward<MapFunction>(mapFunction));
}

template<typename DestinationVector, typename Collection>
inline auto copyToVectorSpecialization(const Collection& collection) -> DestinationVector
{
DestinationVector result;
// FIXME: Use std::size when available on all compilers.
result.reserveInitialCapacity(collection.size());
for (auto& item : collection)
result.uncheckedAppend(item);
return result;
}

template<typename DestinationItemType, typename Collection>
inline auto copyToVectorOf(const Collection& collection) -> Vector<DestinationItemType>
{
@@ -1657,6 +1668,7 @@ using WTF::UnsafeVectorOverflow;
using WTF::Vector;
using WTF::copyToVector;
using WTF::copyToVectorOf;
using WTF::copyToVectorSpecialization;
using WTF::removeRepeatedElements;

#endif // WTF_Vector_h
@@ -1,3 +1,80 @@
2017-10-11 Sam Weinig <sam@webkit.org>

Remove out-parameter variants of copyToVector
https://bugs.webkit.org/show_bug.cgi?id=178155

Reviewed by Tim Horton.

* Modules/geolocation/Geolocation.cpp:
(WebCore::Geolocation::stopTimersForOneShots):
(WebCore::Geolocation::cancelAllRequests):
(WebCore::Geolocation::handleError):
(WebCore::Geolocation::makeSuccessCallbacks):
* Modules/indexeddb/IDBDatabase.cpp:
(WebCore::IDBDatabase::transaction):
* Modules/indexeddb/IDBGetAllResult.cpp:
(WebCore::IDBGetAllResult::allBlobFilePaths const):
* Modules/indexeddb/server/MemoryIndex.cpp:
(WebCore::IDBServer::MemoryIndex::notifyCursorsOfValueChange):
(WebCore::IDBServer::MemoryIndex::notifyCursorsOfAllRecordsChanged):
* css/CSSFontSelector.cpp:
(WebCore::CSSFontSelector::dispatchInvalidationCallbacks):
* dom/Document.cpp:
(WebCore::Document::moveNodeIteratorsToNewDocument):
(WebCore::Document::resume):
(WebCore::Document::didAssociateFormControlsTimerFired):
* dom/IdTargetObserverRegistry.cpp:
(WebCore::IdTargetObserverRegistry::notifyObserversInternal):
* dom/MutationObserver.cpp:
(WebCore::MutationObserver::notifyMutationObservers):
* dom/Node.cpp:
(WebCore::Document::invalidateNodeListAndCollectionCaches):
* dom/RadioButtonGroups.cpp:
* dom/ScriptExecutionContext.cpp:
(WebCore::ScriptExecutionContext::dispatchMessagePortEvents):
(WebCore::ScriptExecutionContext::stopActiveDOMObjects):
* loader/appcache/ApplicationCacheGroup.cpp:
(WebCore::ApplicationCacheGroup::checkIfLoadIsComplete):
(WebCore::ApplicationCacheGroup::deliverDelayedMainResources):
* loader/cache/MemoryCache.cpp:
(WebCore::MemoryCache::forEachResource):
(WebCore::MemoryCache::pruneDeadResourcesToSize):
* page/DOMWindow.cpp:
(WebCore::DOMWindow::willDestroyCachedFrame):
(WebCore::DOMWindow::willDestroyDocumentInFrame):
(WebCore::DOMWindow::willDetachDocumentFromFrame):
(WebCore::DOMWindow::disconnectDOMWindowProperties):
(WebCore::DOMWindow::reconnectDOMWindowProperties):
* page/FrameView.cpp:
(WebCore::collectAndProtectWidgets):
* page/MemoryRelease.cpp:
(WebCore::releaseCriticalMemory):
* page/Performance.cpp:
(WebCore::Performance::queueEntry):
* platform/cocoa/PasteboardCocoa.mm:
(WebCore::Pasteboard::typesForLegacyUnsafeBindings):
* platform/graphics/cocoa/FontCacheCoreText.cpp:
(WebCore::FontCache::systemFontFamilies):
* platform/ios/PlatformPasteboardIOS.mm:
(WebCore::PlatformPasteboard::typesSafeForDOMToReadAndWrite const):
* platform/ios/WebCoreMotionManager.mm:
(-[WebCoreMotionManager sendAccelerometerData:]):
(-[WebCoreMotionManager sendMotionData:withHeading:]):
* platform/mac/PlatformPasteboardMac.mm:
(WebCore::PlatformPasteboard::typesSafeForDOMToReadAndWrite const):
* platform/network/cocoa/WebCoreNSURLSession.mm:
(-[WebCoreNSURLSession invalidateAndCancel]):
* rendering/RenderBlock.cpp:
(WebCore::RenderBlock::endAndCommitUpdateScrollInfoAfterLayoutTransaction):
* rendering/RenderBlockLineLayout.cpp:
(WebCore::setLogicalWidthForTextRun):
* rendering/RenderDeprecatedFlexibleBox.cpp:
(WebCore::FlexBoxIterator::next):
* rendering/RenderTableSection.cpp:
(WebCore::RenderTableSection::paintObject):

Replace out-parameter based copyToVector, with one that returns a Vector.

2017-10-12 Yusuke Suzuki <utatane.tea@gmail.com>

Support integrity="" on module scripts
@@ -83505,8 +83582,6 @@
(WebCore::CaptionUserPreferencesMediaAF::setInterestedInCaptionPreferenceChanges):
* page/DOMWindow.cpp:
(WebCore::DOMWindow::postMessage):
* page/DeviceController.cpp:
(WebCore::DeviceController::addDeviceEventListener):
* page/EventHandler.cpp:
(WebCore::EventHandler::scheduleHoverStateUpdate):
* page/EventSource.cpp:
@@ -543,9 +543,7 @@ void Geolocation::stopTimer(GeoNotifierVector& notifiers)

void Geolocation::stopTimersForOneShots()
{
GeoNotifierVector copy;
copyToVector(m_oneShots, copy);

auto copy = copyToVector(m_oneShots);
stopTimer(copy);
}

@@ -571,8 +569,7 @@ void Geolocation::cancelRequests(GeoNotifierVector& notifiers)

void Geolocation::cancelAllRequests()
{
GeoNotifierVector copy;
copyToVector(m_oneShots, copy);
auto copy = copyToVector(m_oneShots);
cancelRequests(copy);
m_watchers.getNotifiersVector(copy);
cancelRequests(copy);
@@ -599,8 +596,7 @@ void Geolocation::copyToSet(const GeoNotifierVector& src, GeoNotifierSet& dest)

void Geolocation::handleError(PositionError& error)
{
GeoNotifierVector oneShotsCopy;
copyToVector(m_oneShots, oneShotsCopy);
auto oneShotsCopy = copyToVector(m_oneShots);

GeoNotifierVector watchersCopy;
m_watchers.getNotifiersVector(watchersCopy);
@@ -651,8 +647,7 @@ void Geolocation::makeSuccessCallbacks(Geoposition& position)
ASSERT(lastPosition());
ASSERT(isAllowed());

GeoNotifierVector oneShotsCopy;
copyToVector(m_oneShots, oneShotsCopy);
auto oneShotsCopy = copyToVector(m_oneShots);

GeoNotifierVector watchersCopy;
m_watchers.getNotifiersVector(watchersCopy);
@@ -191,8 +191,7 @@ ExceptionOr<Ref<IDBTransaction>> IDBDatabase::transaction(StringOrVectorOfString
for (auto& objectStore : objectStores)
objectStoreSet.add(objectStore);

objectStores.clear();
copyToVector(objectStoreSet, objectStores);
objectStores = copyToVector(objectStoreSet);

for (auto& objectStoreName : objectStores) {
if (m_info.hasObjectStore(objectStoreName))
@@ -107,10 +107,7 @@ Vector<String> IDBGetAllResult::allBlobFilePaths() const
pathSet.add(path);
}

Vector<String> paths;
copyToVector(pathSet, paths);

return paths;
return copyToVector(pathSet);
}

} // namespace WebCore
@@ -79,17 +79,13 @@ void MemoryIndex::objectStoreCleared()

void MemoryIndex::notifyCursorsOfValueChange(const IDBKeyData& indexKey, const IDBKeyData& primaryKey)
{
Vector<MemoryIndexCursor*> cursors;
copyToVector(m_cleanCursors, cursors);
for (auto* cursor : cursors)
for (auto* cursor : copyToVector(m_cleanCursors))
cursor->indexValueChanged(indexKey, primaryKey);
}

void MemoryIndex::notifyCursorsOfAllRecordsChanged()
{
Vector<MemoryIndexCursor*> cursors;
copyToVector(m_cleanCursors, cursors);
for (auto* cursor : cursors)
for (auto* cursor : copyToVector(m_cleanCursors))
cursor->indexRecordsAllChanged();

ASSERT(m_cleanCursors.isEmpty());
@@ -239,10 +239,8 @@ void CSSFontSelector::dispatchInvalidationCallbacks()
{
++m_version;

Vector<FontSelectorClient*> clients;
copyToVector(m_clients, clients);
for (size_t i = 0; i < clients.size(); ++i)
clients[i]->fontsNeedUpdate(*this);
for (auto& client : copyToVector(m_clients))
client->fontsNeedUpdate(*this);
}

void CSSFontSelector::fontLoaded()
@@ -4037,9 +4037,7 @@ void Document::detachNodeIterator(NodeIterator* ni)

void Document::moveNodeIteratorsToNewDocument(Node& node, Document& newDocument)
{
Vector<NodeIterator*> nodeIterators;
copyToVector(m_nodeIterators, nodeIterators);
for (auto* it : nodeIterators) {
for (auto* it : copyToVector(m_nodeIterators)) {
if (&it->root() == &node) {
detachNodeIterator(it);
newDocument.attachNodeIterator(it);
@@ -4827,9 +4825,7 @@ void Document::resume(ActiveDOMObject::ReasonForSuspension reason)
if (!m_isSuspended)
return;

Vector<Element*> elements;
copyToVector(m_documentSuspensionCallbackElements, elements);
for (auto* element : elements)
for (auto* element : copyToVector(m_documentSuspensionCallbackElements))
element->resumeFromDocumentSuspension();

if (renderView())
@@ -6869,10 +6865,7 @@ void Document::didAssociateFormControlsTimerFired()
if (!frame() || !frame()->page())
return;

Vector<RefPtr<Element>> associatedFormControls;
copyToVector(m_associatedFormControls, associatedFormControls);

frame()->page()->chrome().client().didAssociateFormControls(associatedFormControls);
frame()->page()->chrome().client().didAssociateFormControls(copyToVector(m_associatedFormControls));
m_associatedFormControls.clear();
}

0 comments on commit 806cb3b

Please sign in to comment.