source: webkit/trunk/Source/WebKit/UIProcess/StatisticsRequest.cpp

Last change on this file was 290026, checked in by Chris Dumez, 3 years ago

Clean up / optimize call sites constructing vectors
https://bugs.webkit.org/show_bug.cgi?id=236748

Reviewed by Dean Jackson.

Clean up / optimize call sites constructing vectors:

  • Use Vector::map() / WTF::map() where appropriate

Source/JavaScriptCore:

  • Replace Vector::reserveCapacity() with Vector::reserveInitialCapacity() where appropriate
  • Replace Vector::append() with Vector::uncheckedAppend() where appropriate
  • Leverage the fact that Vector<Ref<Foo>> is now copyable (Because Ref<> now has a copy constructor)
  • Call crossThreadCopy() to isolate-copy a Vector() without iterating.
  • Leverage Vector constructor that takes in an intialization list in more cases
  • Leverage Vector::from() in more cases to simplify vector construction in some case.
  • Drop unnecessary calls to Vector::reserve*Capacity() before calling Vector::append(T*, size_t) since the append() implementation already does this for us.
  • Leverage copyToVector() and copyToVectorOf<> in more cases
  • Call shrinkToFit() in some cases where we reserve capacity and then append() but may not append() as much as we reserved.
  • b3/air/AirCode.cpp:

(JSC::B3::Air::Code::setNumEntrypoints):

  • bytecompiler/NodesCodegen.cpp:

(JSC::ArrayPatternNode::emitDirectBinding):

  • dfg/DFGInPlaceAbstractState.cpp:

(JSC::DFG::setLiveValues):

  • dfg/DFGLivenessAnalysisPhase.cpp:
  • dfg/DFGScoreBoard.h:

(JSC::DFG::ScoreBoard::ScoreBoard):

  • inspector/agents/InspectorDebuggerAgent.cpp:

(Inspector::parseBreakpointOptions):

  • inspector/remote/socket/RemoteInspectorMessageParser.cpp:

(Inspector::MessageParser::pushReceivedData):

  • parser/VariableEnvironment.cpp:

(JSC::CompactTDZEnvironment::CompactTDZEnvironment):

  • wasm/WasmWorklist.cpp:

(JSC::Wasm::Worklist::Worklist):

Source/WebCore:

  • Replace Vector::reserveCapacity() with Vector::reserveInitialCapacity() where appropriate
  • Replace Vector::append() with Vector::uncheckedAppend() where appropriate
  • Leverage the fact that Vector<Ref<Foo>> is now copyable (Because Ref<> now has a copy constructor)
  • Call crossThreadCopy() to isolate-copy a Vector() without iterating.
  • Leverage Vector constructor that takes in an intialization list in more cases
  • Leverage Vector::from() in more cases to simplify vector construction in some case.
  • Drop unnecessary calls to Vector::reserve*Capacity() before calling Vector::append(T*, size_t) since the append() implementation already does this for us.
  • Leverage copyToVector() and copyToVectorOf<> in more cases
  • Call shrinkToFit() in some cases where we reserve capacity and then append() but may not append() as much as we reserved.
  • Modules/async-clipboard/Clipboard.cpp:

(WebCore::Clipboard::read):
(WebCore::Clipboard::ItemWriter::didSetAllData):

  • Modules/encryptedmedia/MediaKeySession.cpp:

(WebCore::MediaKeySession::updateKeyStatuses):

  • Modules/entriesapi/FileSystemEntriesCallback.cpp:

(WebCore::FileSystemEntriesCallback::scheduleCallback):
(WebCore::copyVector): Deleted.

  • Modules/entriesapi/HTMLInputElementEntriesAPI.cpp:

(WebCore::HTMLInputElementEntriesAPI::webkitEntries):

  • Modules/geolocation/GeolocationController.cpp:

(WebCore::GeolocationController::positionChanged):
(WebCore::GeolocationController::errorOccurred):

  • Modules/indexeddb/IDBDatabase.cpp:

(WebCore::IDBDatabase::stop):

  • Modules/indexeddb/IDBGetAllResult.cpp:

(WebCore::IDBGetAllResult::isolatedCopy):

  • Modules/indexeddb/IDBGetResult.cpp:

(WebCore::IDBGetResult::isolatedCopy):

  • Modules/indexeddb/IDBKeyPath.cpp:

(WebCore::isolatedCopy): Deleted.

  • Modules/indexeddb/IDBKeyPath.h:

(WebCore::isolatedCopy): Deleted.

  • Modules/indexeddb/IDBTransaction.cpp:

(WebCore::IDBTransaction::abortInProgressOperations):

  • Modules/indexeddb/client/IDBConnectionProxy.cpp:

(WebCore::IDBClient::removeItemsMatchingCurrentThread):

  • Modules/indexeddb/server/MemoryObjectStore.cpp:

(WebCore::IDBServer::MemoryObjectStore::deleteAllIndexes):

  • Modules/indexeddb/server/SQLiteIDBCursor.cpp:

(WebCore::IDBServer::SQLiteIDBCursor::currentData):

  • Modules/indexeddb/shared/IDBDatabaseInfo.cpp:

(WebCore::IDBDatabaseInfo::objectStoreNames const):

  • Modules/indexeddb/shared/IDBIndexInfo.cpp:

(WebCore::IDBIndexInfo::isolatedCopy const):

  • Modules/indexeddb/shared/IDBObjectStoreInfo.cpp:

(WebCore::IDBObjectStoreInfo::isolatedCopy const):
(WebCore::IDBObjectStoreInfo::indexNames const):

  • Modules/indexeddb/shared/IDBTransactionInfo.cpp:

(WebCore::IDBTransactionInfo::isolatedCopy):

  • Modules/indexeddb/shared/IndexKey.cpp:

(WebCore::IndexKey::isolatedCopy const):

  • Modules/mediastream/MediaStream.cpp:

(WebCore::MediaStream::clone):

  • Modules/mediastream/MediaStreamTrack.cpp:

(WebCore::capabilityStringVector):

  • Modules/mediastream/MediaTrackConstraints.cpp:

(WebCore::convertAdvancedToInternalForm):

  • Modules/mediastream/SFrameUtils.cpp:

(WebCore::toRbsp):

  • Modules/remoteplayback/RemotePlayback.cpp:

(WebCore::RemotePlayback::availabilityChanged):

  • Modules/speech/SpeechRecognition.cpp:

(WebCore::SpeechRecognition::didReceiveResult):

  • Modules/webauthn/cbor/CBORValue.cpp:

(cbor::CBORValue::CBORValue):

  • Modules/webauthn/fido/AuthenticatorGetInfoResponse.cpp:

(fido::toArrayValue):

  • Modules/webauthn/fido/DeviceRequestConverter.cpp:

(fido::convertParametersToCBOR):

  • Modules/webauthn/fido/Pin.cpp:

(fido::pin::encodeRawPublicKey):

  • Modules/webdatabase/DatabaseTracker.cpp:

(WebCore::DatabaseTracker::databaseNames):
(WebCore::isolatedCopy): Deleted.

  • accessibility/AXObjectCache.cpp:

(WebCore::AXObjectCache::notificationPostTimerFired):

  • accessibility/isolatedtree/AXIsolatedObject.cpp:

(WebCore::AXIsolatedObject::setMathscripts):
(WebCore::AXIsolatedObject::setObjectVectorProperty):

  • accessibility/isolatedtree/AXIsolatedTree.cpp:

(WebCore::AXIsolatedTree::objectsForIDs const):
(WebCore::AXIsolatedTree::collectNodeChangesForSubtree):

  • animation/CSSPropertyAnimation.cpp:

(WebCore::CSSPropertyAnimationWrapperMap::CSSPropertyAnimationWrapperMap):

  • bindings/js/SerializedScriptValue.cpp:

(WebCore::CloneDeserializer::readString):
(WebCore::SerializedScriptValue::blobURLs const):

  • crypto/mac/CryptoAlgorithmECDSAMac.cpp:

(WebCore::signECDSA):
(WebCore::verifyECDSA):

  • crypto/mac/CryptoKeyECMac.cpp:

(WebCore::CryptoKeyEC::platformExportSpki const):
(WebCore::CryptoKeyEC::platformExportPkcs8 const):

  • crypto/mac/CryptoKeyRSAMac.cpp:

(WebCore::CryptoKeyRSA::exportSpki const):
(WebCore::CryptoKeyRSA::exportPkcs8 const):

  • css/CSSBasicShapes.cpp:

(WebCore::CSSBasicShapePolygon::cssText const):

  • css/CSSComputedStyleDeclaration.cpp:

(WebCore::ComputedStyleExtractor::copyPropertiesInSet):
(WebCore::ComputedStyleExtractor::copyProperties):

  • css/CSSFontFace.cpp:

(WebCore::iterateClients):

  • css/CSSFontFaceSet.cpp:

(WebCore::CSSFontFaceSet::matchingFacesExcludingPreinstalledFonts):
(WebCore::CSSFontFaceSet::fontFace):

  • css/CSSKeyframesRule.cpp:

(WebCore::StyleRuleKeyframes::StyleRuleKeyframes):

  • css/StyleProperties.cpp:

(WebCore::StyleProperties::copyPropertiesInSet const):
(WebCore::DeferredStyleProperties::DeferredStyleProperties):

  • css/StyleRule.cpp:

(WebCore::DeferredStyleGroupRuleList::DeferredStyleGroupRuleList):
(WebCore::StyleRuleGroup::StyleRuleGroup):

  • css/calc/CSSCalcOperationNode.h:
  • css/calc/CSSCalcValue.cpp:

(WebCore::createCSS):

  • display/css/DisplayBoxDecorationPainter.cpp:

(WebCore::Display::BorderPainter::clipBorderSidePolygon const):
(WebCore::Display::BorderPainter::drawLineForBoxSide const):

  • dom/DOMRectList.cpp:

(WebCore::DOMRectList::DOMRectList):

  • dom/Document.cpp:

(WebCore::Document::updateElementsAffectedByMediaQueries):
(WebCore::Document::didAssociateFormControlsTimerFired):

  • dom/ElementData.cpp:

(WebCore::UniqueElementData::UniqueElementData):

  • dom/EventListenerMap.cpp:

(WebCore::EventListenerMap::eventTypes const):

  • dom/TreeScopeOrderedMap.cpp:

(WebCore::TreeScopeOrderedMap::keys const):

  • editing/CompositeEditCommand.cpp:

(WebCore::copyMarkers):

  • editing/Editor.cpp:

(WebCore::editableTextListsAtPositionInDescendingOrder):

  • fileapi/FileList.cpp:

(WebCore::FileList::paths const):

  • history/HistoryItem.cpp:

(WebCore::HistoryItem::HistoryItem):
(WebCore::m_formData):
(WebCore::m_identifier):

  • html/FileInputType.cpp:

(WebCore::FileInputType::setFiles):
(WebCore::FileInputType::filesChosen):

  • html/LinkIconCollector.cpp:

(WebCore::LinkIconCollector::iconsOfTypes):

  • html/URLSearchParams.cpp:

(WebCore::URLSearchParams::getAll const):

  • layout/formattingContexts/inline/InlineLineBuilder.cpp:

(WebCore::Layout::LineBuilder::layoutInlineContent):

  • loader/DocumentLoader.cpp:

(WebCore::DocumentLoader::startIconLoading):
(WebCore::DocumentLoader::setActiveContentRuleListActionPatterns):

  • loader/TextTrackLoader.cpp:

(WebCore::TextTrackLoader::getNewCues):

  • loader/archive/cf/LegacyWebArchive.cpp:

(WebCore::LegacyWebArchive::createFromSelection):

  • page/CaptionUserPreferencesMediaAF.cpp:

(WebCore::CaptionUserPreferencesMediaAF::preferredAudioCharacteristics const):

  • page/DOMWindow.cpp:

(WebCore::DOMWindow::dispatchAllPendingBeforeUnloadEvents):

  • page/IntersectionObserver.cpp:

(WebCore::IntersectionObserver::create):

  • page/Page.cpp:

(WebCore::Page::replaceRangesWithText):

  • page/csp/ContentSecurityPolicy.cpp:

(WebCore::ContentSecurityPolicy::responseHeaders const):

  • page/csp/ContentSecurityPolicyResponseHeaders.cpp:

(WebCore::ContentSecurityPolicyResponseHeaders::isolatedCopy const):

  • page/mac/ImageOverlayControllerMac.mm:

(WebCore::ImageOverlayController::updateDataDetectorHighlights):

  • page/mac/ServicesOverlayController.mm:

(WebCore::ServicesOverlayController::buildSelectionHighlight):
(WebCore::ServicesOverlayController::handleClick):

  • page/scrolling/AsyncScrollingCoordinator.cpp:

(WebCore::AsyncScrollingCoordinator::childrenOfNode const):

  • page/scrolling/ScrollSnapOffsetsInfo.cpp:

(WebCore::convertOffsetInfo):

  • platform/Length.cpp:

(WebCore::makeCalculated):

  • platform/animation/AnimationList.cpp:

(WebCore::AnimationList::AnimationList):

  • platform/cocoa/PlaybackSessionModelMediaElement.mm:

(WebCore::PlaybackSessionModelMediaElement::audioMediaSelectionOptions const):

  • platform/encryptedmedia/CDMProxy.cpp:

(WebCore::KeyStore::convertToJSKeyStatusVector const):

  • platform/graphics/FloatPolygon.cpp:

(WebCore::FloatPolygon::overlappingEdges const):

  • platform/graphics/FloatQuad.cpp:

(WebCore::boundingBoxes):

  • platform/graphics/avfoundation/objc/CDMInstanceFairPlayStreamingAVFObjC.mm:

(WebCore::CDMInstanceSessionFairPlayStreamingAVFObjC::updateLicense):

  • platform/graphics/ca/TileGrid.cpp:

(WebCore::TileGrid::removeTiles):
(WebCore::TileGrid::removeAllTiles):

  • platform/graphics/ca/TileGrid.h:
  • platform/graphics/cg/ImageUtilitiesCG.cpp:

(WebCore::findImagesForTranscoding):
(WebCore::transcodeImages):

  • platform/graphics/cocoa/FontCacheCoreText.cpp:

(WebCore::findClosestFont):
(WebCore::FontCache::getFontSelectionCapabilitiesInFamily):

  • platform/mediastream/RealtimeMediaSource.cpp:

(WebCore::RealtimeMediaSource::fitnessDistance):

  • platform/network/CacheValidation.cpp:

(WebCore::collectVaryingRequestHeadersInternal):

  • platform/network/FormData.cpp:

(WebCore::FormData::isolatedCopy const):

  • platform/network/SocketStreamHandleImpl.cpp:

(WebCore::SocketStreamHandleImpl::platformSendHandshake):

  • platform/network/cocoa/NetworkStorageSessionCocoa.mm:
  • platform/text/LocaleICU.cpp:

(WebCore::LocaleICU::createLabelVector):
(WebCore::createFallbackMonthLabels):
(WebCore::createFallbackAMPMLabels):

  • platform/text/LocaleNone.cpp:

(WebCore::LocaleNone::monthLabels):
(WebCore::LocaleNone::shortMonthLabels):
(WebCore::LocaleNone::timeAMPMLabels):

  • platform/text/cocoa/LocaleCocoa.mm:

(WebCore::LocaleCocoa::monthLabels):
(WebCore::LocaleCocoa::shortMonthLabels):
(WebCore::LocaleCocoa::standAloneMonthLabels):
(WebCore::LocaleCocoa::shortStandAloneMonthLabels):
(WebCore::LocaleCocoa::timeAMPMLabels):

  • plugins/DOMMimeTypeArray.cpp:

(WebCore::DOMMimeTypeArray::supportedPropertyNames const):
(WebCore::DOMMimeTypeArray::supportedPropertyNames): Deleted.

  • plugins/DOMMimeTypeArray.h:
  • plugins/DOMPlugin.cpp:

(WebCore::makeMimeTypes):
(WebCore::DOMPlugin::supportedPropertyNames const):
(WebCore::DOMPlugin::supportedPropertyNames): Deleted.

  • plugins/DOMPlugin.h:
  • plugins/DOMPluginArray.cpp:

(WebCore::DOMPluginArray::supportedPropertyNames const):
(WebCore::DOMPluginArray::supportedPropertyNames): Deleted.

  • plugins/DOMPluginArray.h:
  • rendering/LayerAncestorClippingStack.cpp:

(WebCore::LayerAncestorClippingStack::LayerAncestorClippingStack):
(WebCore::LayerAncestorClippingStack::compositedClipData const):

  • rendering/RenderBoxModelObject.cpp:

(WebCore::RenderBoxModelObject::clipBorderSidePolygon):

  • rendering/RenderElement.cpp:

(WebCore::RenderElement::drawLineForBoxSide const):

  • rendering/RenderGrid.cpp:

(WebCore::RenderGrid::trackSizesForComputedStyle const):

  • style/ClassChangeInvalidation.cpp:

(WebCore::Style::collectClasses):

  • style/StyleBuilderConverter.h:

(WebCore::Style::BuilderConverter::convertTo100PercentMinusLength):

  • testing/MockCDMFactory.cpp:

(WebCore::MockCDMInstanceSession::updateLicense):
(WebCore::MockCDMInstanceSession::removeSessionData):

  • workers/service/server/SWServer.cpp:

(WebCore::SWServer::getRegistrations):

Source/WebKit:

  • Replace Vector::reserveCapacity() with Vector::reserveInitialCapacity() where appropriate
  • Replace Vector::append() with Vector::uncheckedAppend() where appropriate
  • Leverage the fact that Vector<Ref<Foo>> is now copyable (Because Ref<> now has a copy constructor)
  • Call crossThreadCopy() to isolate-copy a Vector() without iterating.
  • Leverage Vector constructor that takes in an intialization list in more cases
  • Leverage Vector::from() in more cases to simplify vector construction in some case.
  • Drop unnecessary calls to Vector::reserve*Capacity() before calling Vector::append(T*, size_t) since the append() implementation already does this for us.
  • Leverage copyToVector() and copyToVectorOf<> in more cases
  • Call shrinkToFit() in some cases where we reserve capacity and then append() but may not append() as much as we reserved.
  • NetworkProcess/WebStorage/LocalStorageDatabaseTracker.cpp:

(WebKit::LocalStorageDatabaseTracker::originDetailsCrossThreadCopy):

  • NetworkProcess/cache/CacheStorageEngineCaches.cpp:

(WebKit::CacheStorage::Caches::cacheInfos):

  • Shared/API/APIArray.cpp:

(API::Array::createStringArray):
(API::Array::copy):

  • Shared/API/APIDictionary.cpp:

(API::Dictionary::keys const):

  • Shared/UserData.cpp:

(WebKit::transformGraph):

  • Shared/WebContextMenuItem.cpp:

(WebKit::WebContextMenuItem::create):
(WebKit::WebContextMenuItem::submenuItemsAsAPIArray const):

  • Shared/WebContextMenuItemData.cpp:

(WebKit::kitItems):
(WebKit::coreItems):

  • UIProcess/API/APIWebAuthenticationPanel.cpp:

(API::WebAuthenticationPanel::WebAuthenticationPanel):

  • UIProcess/API/APIWebsitePolicies.cpp:

(API::WebsitePolicies::copy const):
(API::WebsitePolicies::data):

  • UIProcess/API/C/WKPage.cpp:

(API::toAPIObjectVector):
(WKPageSetPageContextMenuClient):
(WKPageSetPageFindMatchesClient):
(WKPageSetPageLoaderClient):

  • UIProcess/Cocoa/VideoFullscreenManagerProxy.mm:

(WebKit::VideoFullscreenManagerProxy::forEachSession):

  • UIProcess/Gamepad/UIGamepadProvider.cpp:

(WebKit::UIGamepadProvider::snapshotGamepads):

  • UIProcess/Network/NetworkProcessProxy.cpp:

(WebKit::NetworkProcessProxy::allNetworkProcesses):
(WebKit::NetworkProcessProxy::updatePrevalentDomainsToBlockCookiesFor):

  • UIProcess/Notifications/WebNotificationManagerProxy.cpp:

(WebKit::WebNotificationManagerProxy::providerDidRemoveNotificationPolicies):

  • UIProcess/Notifications/WebNotificationProvider.cpp:

(WebKit::WebNotificationProvider::clearNotifications):

  • UIProcess/StatisticsRequest.cpp:

(WebKit::StatisticsRequest::completedRequest):

  • UIProcess/UserContent/WebUserContentControllerProxy.cpp:

(WebKit::WebUserContentControllerProxy::removeAllUserScripts):
(WebKit::WebUserContentControllerProxy::removeAllUserStyleSheets):

  • UIProcess/WebAuthentication/Cocoa/WebAuthenticationPanelClient.mm:

(WebKit::WebAuthenticationPanelClient::selectAssertionResponse const):

  • UIProcess/WebAuthentication/fido/CtapAuthenticator.cpp:

(WebKit::CtapAuthenticator::continueGetNextAssertionAfterResponseReceived):

  • UIProcess/WebBackForwardList.cpp:

(WebKit::WebBackForwardList::addItem):
(WebKit::WebBackForwardList::clear):
(WebKit::WebBackForwardList::restoreFromState):

  • UIProcess/WebPageProxy.cpp:

(WebKit::WebPageProxy::runJavaScriptInFrameInScriptWorld):
(WebKit::WebPageProxy::speechSynthesisVoiceList):

  • UIProcess/WebsiteData/WebsiteDataStore.cpp:

(WebKit::WebsiteDataStore::fetchDataAndApply):
(WebKit::WebsiteDataStore::parametersFromEachWebsiteDataStore):

  • UIProcess/mac/WKTextFinderClient.mm:

(-[WKTextFinderClient replaceMatches:withString:inSelectionOnly:resultCollector:]):

  • WebProcess/GPU/media/RemoteRemoteCommandListener.cpp:

(WebKit::RemoteRemoteCommandListener::updateSupportedCommands):

  • WebProcess/InjectedBundle/API/c/WKBundlePage.cpp:

(contextMenuItems):
(WKBundlePageCopyOriginsWithApplicationCache):

  • WebProcess/InjectedBundle/InjectedBundlePageContextMenuClient.cpp:

(WebKit::InjectedBundlePageContextMenuClient::getCustomMenuFromDefaultItems):

  • WebProcess/InjectedBundle/InjectedBundlePageFormClient.cpp:

(WebKit::InjectedBundlePageFormClient::didAssociateFormControls):

  • WebProcess/Network/WebSocketStream.cpp:

(WebKit::WebSocketStream::networkProcessCrashed):

  • WebProcess/Network/webrtc/WebRTCResolver.cpp:

(WebKit::WebRTCResolver::setResolvedAddress):

  • WebProcess/WebCoreSupport/WebResourceLoadObserver.cpp:

(WebKit::WebResourceLoadObserver::takeStatistics):

  • WebProcess/WebPage/FindController.cpp:

(WebKit::FindController::replaceMatches):

  • WebProcess/WebPage/RemoteLayerTree/PlatformCAAnimationRemote.mm:

(WebKit::toKeyframeValueVector):
(WebKit::PlatformCAAnimationRemote::setValues):
(WebKit::PlatformCAAnimationRemote::setTimingFunctions):

  • WebProcess/WebPage/ViewGestureGeometryCollector.cpp:

(WebKit::ViewGestureGeometryCollector::computeTextLegibilityScales):

  • WebProcess/WebPage/WebPage.cpp:

(WebKit::WebPage::trackedRepaintRects):
(WebKit::dumpHistoryItem):

Source/WTF:

  • Replace Vector::reserveCapacity() with Vector::reserveInitialCapacity() where appropriate
  • Replace Vector::append() with Vector::uncheckedAppend() where appropriate
  • Leverage the fact that Vector<Ref<Foo>> is now copyable (Because Ref<> now has a copy constructor)
  • Call crossThreadCopy() to isolate-copy a Vector() without iterating.
  • Leverage Vector constructor that takes in an intialization list in more cases
  • Leverage Vector::from() in more cases to simplify vector construction in some case.
  • Drop unnecessary calls to Vector::reserve*Capacity() before calling Vector::append(T*, size_t) since the append() implementation already does this for us.
  • Leverage copyToVector() and copyToVectorOf<> in more cases
  • Call shrinkToFit() in some cases where we reserve capacity and then append() but may not append() as much as we reserved.
  • wtf/Language.cpp:

(WTF::userPreferredLanguages):
(WTF::isolatedCopy): Deleted.

File size: 3.9 KB
Line 
1/*
2 * Copyright (C) 2013 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#include "config.h"
27#include "StatisticsRequest.h"
28
29#include "APIArray.h"
30#include "APIDictionary.h"
31
32namespace WebKit {
33
34StatisticsRequest::StatisticsRequest(Ref<DictionaryCallback>&& callback)
35 : m_callback(WTFMove(callback))
36{
37}
38
39StatisticsRequest::~StatisticsRequest()
40{
41 if (m_callback)
42 m_callback->invalidate();
43}
44
45uint64_t StatisticsRequest::addOutstandingRequest()
46{
47 static std::atomic<int64_t> uniqueRequestID;
48
49 uint64_t requestID = ++uniqueRequestID;
50 m_outstandingRequests.add(requestID);
51 return requestID;
52}
53
54static void addToDictionaryFromHashMap(API::Dictionary* dictionary, const HashMap<String, uint64_t>& map)
55{
56 HashMap<String, uint64_t>::const_iterator end = map.end();
57 for (HashMap<String, uint64_t>::const_iterator it = map.begin(); it != end; ++it)
58 dictionary->set(it->key, RefPtr<API::UInt64>(API::UInt64::create(it->value)).get());
59}
60
61static Ref<API::Dictionary> createDictionaryFromHashMap(const HashMap<String, uint64_t>& map)
62{
63 Ref<API::Dictionary> result = API::Dictionary::create();
64 addToDictionaryFromHashMap(result.ptr(), map);
65 return result;
66}
67
68void StatisticsRequest::completedRequest(uint64_t requestID, const StatisticsData& data)
69{
70 ASSERT(m_outstandingRequests.contains(requestID));
71 m_outstandingRequests.remove(requestID);
72
73 if (!m_responseDictionary)
74 m_responseDictionary = API::Dictionary::create();
75
76 // FIXME (Multi-WebProcess) <rdar://problem/13200059>: This code overwrites any previous response data received.
77 // When getting responses from multiple WebProcesses we need to combine items instead of clobbering them.
78
79 addToDictionaryFromHashMap(m_responseDictionary.get(), data.statisticsNumbers);
80
81 if (!data.javaScriptProtectedObjectTypeCounts.isEmpty())
82 m_responseDictionary->set("JavaScriptProtectedObjectTypeCounts", createDictionaryFromHashMap(data.javaScriptProtectedObjectTypeCounts));
83 if (!data.javaScriptObjectTypeCounts.isEmpty())
84 m_responseDictionary->set("JavaScriptObjectTypeCounts", createDictionaryFromHashMap(data.javaScriptObjectTypeCounts));
85
86 if (!data.webCoreCacheStatistics.isEmpty()) {
87 auto cacheStatistics = data.webCoreCacheStatistics.map([](auto& statistic) -> RefPtr<API::Object> {
88 return createDictionaryFromHashMap(statistic);
89 });
90 m_responseDictionary->set("WebCoreCacheStatistics", API::Array::create(WTFMove(cacheStatistics)));
91 }
92
93 if (m_outstandingRequests.isEmpty()) {
94 m_callback->performCallbackWithReturnValue(m_responseDictionary.get());
95 m_callback = nullptr;
96 }
97}
98
99} // namespace WebKit
Note: See TracBrowser for help on using the repository browser.