Eliminate some cases of double hashing, other related refactoring
authordarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 20 Nov 2017 00:56:27 +0000 (00:56 +0000)
committerdarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 20 Nov 2017 00:56:27 +0000 (00:56 +0000)
commitc7d04a0053f4eacc7644c0ebdcadae27f936470b
treebf925f032d72eba8b4d636466b7602214fcf3fc3
parent881f4cda99c58bf235ade80984b6741db2ea3900
Eliminate some cases of double hashing, other related refactoring
https://bugs.webkit.org/show_bug.cgi?id=179867

Reviewed by Sam Weinig.

Source/WebCore:

* Modules/indexeddb/IDBTransaction.cpp:
(WebCore::IDBTransaction::objectStore): Use get instead of find.

* Modules/mediasource/MediaSourceRegistry.cpp:
(WebCore::MediaSourceRegistry::unregisterURL): Use take instead of find/remove.

* accessibility/AXObjectCache.cpp:
(WebCore::AXObjectCache::~AXObjectCache): Call setAXObjectID instead of
using the removeAXID, which doesn't do anything else useful in the destructor.
(WebCore::AXObjectCache::remove): Use take instead of get/remove. Also rearrange
logic to eliminate the removeAXID function.
(WebCore::AXObjectCache::removeAXID): Deleted. This only did two things,
setAXObjectID(0) and remove from m_idsInUse, and was only called in one place
besides the destructor. Clearer to not have this funtion.
(WebCore::AXObjectCache::visiblePositionForTextMarkerData): Use m_idsInUse
directly instead of using a function.

* accessibility/AXObjectCache.h: Deleted removeAXID and isIDinUse.

* dom/Document.cpp:
(WebCore::Document::removedLastRef): Call UserActionElementSet::clear instead
of UserActionElementSet::documentDidRemoveLastRef; new name fo the same function.
(WebCore::Document::updateHoverActiveState): Use a reference when calling
setInActiveChain.

* dom/Element.cpp:
(WebCore::Element::isUserActionElementInActiveChain const): Pass reference
instead of pointer.
(WebCore::Element::isUserActionElementActive const): Ditto.
(WebCore::Element::isUserActionElementFocused const): Ditto.
(WebCore::Element::isUserActionElementHovered const): Ditto.
(WebCore::Element::setActive): Ditto.
(WebCore::Element::setFocus): Ditto.
(WebCore::Element::setHovered): Ditto.
(WebCore::Element::clearHoverAndActiveStatusBeforeDetachingRenderer): Ditto.

* dom/GenericEventQueue.cpp:
(WebCore::GenericEventQueue::resume): Removed unneeded speical case for
empty vector.

* dom/ProcessingInstruction.cpp:
(WebCore::ProcessingInstruction::checkStyleSheet): Updated now that
parseAttributes returns an optional instead of using a boolean "OK" out argument.

* dom/SelectorQuery.cpp:
(WebCore::SelectorQueryCache::add): Use get instead of find.

* dom/UserActionElementSet.cpp:
(WebCore::UserActionElementSet::didDetach): Deleted. Moved to class definition and
named clearActiveAndHovered.
(WebCore::UserActionElementSet::clear): Renamed documentDidRemoveLastRef to clear.
(WebCore::UserActionElementSet::hasFlag const): Renamed from hasFlags and also
take reference and enumeration instead of pointer and unsigned. Makes it clearer
this does not allow null and that it works on a single flag, not a set of flags.
(WebCore::UserActionElementSet::clearFlags): Changed argument types to reference
and OptionSet to make it clear this works on a set of flags.
(WebCore::UserActionElementSet::setFlags): Ditto.

* dom/UserActionElementSet.h: Updated for changes above. Also made some name
changes, and used an enum class instead of an enum.

* html/BaseCheckableInputType.cpp:
(WebCore::BaseCheckableInputType::saveFormControlState const): Updated since
FormControlState is now just a vector, not a class.
* html/FileInputType.cpp:
(WebCore::FileInputType::filesFromFormControlState): Ditto.
(WebCore::FileInputType::restoreFormControlState): Removed unneeded check that
valueSize is a multiple of 2. Code will ignore any extra strings at the end, so
there is no need for the validity check.

* html/FormController.cpp:
(WebCore::serializeFormControlStateTo): Made a non-member function since
FormControlState is now just a vector, not a class.
(WebCore::deserializeFormControlState): Ditto. Also return optional instead
of relying on a special failure state.
(WebCore::SavedFormState::deserialize): Updated for above changes.
(WebCore::SavedFormState::serializeTo const): Ditto.
(WebCore::SavedFormState::appendControlState): Use add instead of both find and add
to avoid double hashing.
(WebCore::SavedFormState::takeControlState): Removed unneeded check for empty
hash table and tweaked coding style.
(WebCore::SavedFormState::referencedFilePaths const): Renamed to remove "get".
(WebCore::FormKeyGenerator::formKey): Use ensure instead of find and add.
(WebCore::FormController::formElementsCharacterCount const): Don't call
saveFormControlState for non-text-form-controls since we ignored those values.
(WebCore::FormController::willDeleteForm): Take a reference.
(WebCore::FormController::restoreControlStateFor): Update since FormControlState
is now a vector.
(WebCore::FormController::restoreControlStateIn): Use is/downcast and update
since FormControlState is now a vector.
(WebCore::FormController::referencedFilePaths): Renamed to remove "get".
(WebCore::FormController::registerFormElementWithState):Take a reference.
(WebCore::FormController::unregisterFormElementWithState): Ditto.

* html/FormController.h: Removed FormControlState class since it was just a
Vector<String> with various unneeded features, such as a "failure" state,
and a never-looked-at type of "skip" or "restore". Updated for other changes
above.

* html/HTMLFormControlElementWithState.cpp:
(WebCore::HTMLFormControlElementWithState::insertedIntoAncestor): Pass reference.
(WebCore::HTMLFormControlElementWithState::removedFromAncestor): Ditto.
* html/HTMLFormControlElementWithState.h: Updated for the above. Also added
support for using is/downcast on this.

* html/HTMLFormElement.cpp:
(WebCore::HTMLFormElement::~HTMLFormElement): Pass reference.

* html/HTMLSelectElement.cpp:
(WebCore::HTMLSelectElement::saveFormControlState const): Use reserveInitialCapacit
and uncheckedAppend.
(WebCore::HTMLSelectElement::restoreFormControlState): Updated since state is now
a vector.
* html/HTMLTextAreaElement.cpp:
(WebCore::HTMLTextAreaElement::saveFormControlState const): Ditto.
* html/HiddenInputType.cpp:
(WebCore::HiddenInputType::saveFormControlState const): Ditto.
* html/InputType.cpp:
(WebCore::InputType::saveFormControlState const): Ditto.

* inspector/agents/InspectorCSSAgent.cpp:
(WebCore::InspectorCSSAgent::forcePseudoState): Use get instead of find/end and got
rid of uneeded special case. In another overload, ue add and remove instead of
a find followed by a set or a remove.
(WebCore::InspectorCSSAgent::asInspectorStyleSheet): Use ensure instead of find/set.
(WebCore::InspectorCSSAgent::didRemoveDOMNode): Use take instead of find/remove.
(WebCore::InspectorCSSAgent::didModifyDOMAttr): Use get instead of find.
* inspector/agents/InspectorCSSAgent.h: Removed unneeded NodeToInspectorStyleSheet
typedef and changed value type to Ref instead of RefPtr.

* inspector/agents/InspectorDOMAgent.cpp:
(WebCore::InspectorDOMAgent::unbind): Use remove instead of contains/remove.
(WebCore::InspectorDOMAgent::nodeForId): Use isValidKey instead of just checking for
0 and use get instead of find.
(WebCore::InspectorDOMAgent::setAttributesAsText): Take out bogus const.
(WebCore::InspectorDOMAgent::moveTo): Ditto.
(WebCore::InspectorDOMAgent::resolveNode): Ditto.
(WebCore::InspectorDOMAgent::isWhitespace): Added FIXME. Use is<Text> instead of
slower nodeType.
* inspector/agents/InspectorDOMAgent.h: Removed bogus const.

* inspector/agents/InspectorLayerTreeAgent.cpp:
(WebCore::InspectorLayerTreeAgent::bind): Use ensure instead of get/set.
(WebCore::InspectorLayerTreeAgent::unbind): Use take instead of find/remove.
(WebCore::InspectorLayerTreeAgent::bindPseudoElement): Use ensure instead of get/set.
(WebCore::InspectorLayerTreeAgent::unbindPseudoElement): Use take instead of
find/remove.

* inspector/agents/InspectorPageAgent.cpp:
(WebCore::InspectorPageAgent::getCookies): Use add instead of contains/add.
(WebCore::InspectorPageAgent::frameDetached): Use take instead of find/remove.
(WebCore::InspectorPageAgent::frameId): Use ensure instead of get/set.
(WebCore::InspectorPageAgent::loaderId): Use ensure instead of get/set.
(WebCore::InspectorPageAgent::findFrameWithSecurityOrigin): Got rid of unneeded
local variable.

* loader/cache/CachedResourceLoader.cpp:
(WebCore::CachedResourceLoader::sessionID const): Tweaked coding style and added
a null check for page.
(WebCore::CachedResourceLoader::requestResource): Call page directly on the frame
instead of first getting the main frame. Also use take instead of find/remove.
(WebCore::CachedResourceLoader::removeCachedResource): Rewrite assertion.

* platform/graphics/FontGenericFamilies.cpp:
(WebCore::setGenericFontFamilyForScript): Use remove instead of find/remove.
Simplified the logic a bit in the add case.

* platform/graphics/ca/GraphicsLayerCA.cpp:
(WebCore::GraphicsLayerCA::pauseAnimation): Use add instead of find/add.
Removed code that said "if (action != Remove) action = Pause" since that is a
no-op; there are only two actions, Remove and Pause.

* rendering/RenderThemeMac.mm:
(WebCore::RenderThemeMac::mediaControlsScript): Use makeString instead of StringBuilder.
(WebCore::RenderThemeMac::systemColor const): Rewrote to use ensure instead of add.
Also crunched the code a little.

* testing/Internals.cpp:
(WebCore::Internals::getReferencedFilePaths const): Updated function name.

* xml/parser/XMLDocumentParser.h: Updated for change below.
* xml/parser/XMLDocumentParserLibxml2.cpp:
(WebCore::attributesStartElementNsHandler): Updated to use std::optional instead of
a separate boolean for AttributeParseState.
(WebCore::parseAttributes): Ditto. Also changed the return value to work the same way.

Source/WTF:

* wtf/text/StringImpl.cpp:
(WTF::StringImpl::containsOnlyWhitespace): Added FIXME.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225037 268f45cc-cd09-0410-ab3c-d52691b4dbfc
38 files changed:
Source/WTF/ChangeLog
Source/WTF/wtf/text/StringImpl.cpp
Source/WebCore/ChangeLog
Source/WebCore/Modules/indexeddb/IDBTransaction.cpp
Source/WebCore/Modules/mediasource/MediaSourceRegistry.cpp
Source/WebCore/accessibility/AXObjectCache.cpp
Source/WebCore/accessibility/AXObjectCache.h
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/Element.cpp
Source/WebCore/dom/GenericEventQueue.cpp
Source/WebCore/dom/ProcessingInstruction.cpp
Source/WebCore/dom/SelectorQuery.cpp
Source/WebCore/dom/UserActionElementSet.cpp
Source/WebCore/dom/UserActionElementSet.h
Source/WebCore/html/BaseCheckableInputType.cpp
Source/WebCore/html/FileInputType.cpp
Source/WebCore/html/FormController.cpp
Source/WebCore/html/FormController.h
Source/WebCore/html/HTMLFormControlElementWithState.cpp
Source/WebCore/html/HTMLFormControlElementWithState.h
Source/WebCore/html/HTMLFormElement.cpp
Source/WebCore/html/HTMLSelectElement.cpp
Source/WebCore/html/HTMLTextAreaElement.cpp
Source/WebCore/html/HiddenInputType.cpp
Source/WebCore/html/InputType.cpp
Source/WebCore/inspector/agents/InspectorCSSAgent.cpp
Source/WebCore/inspector/agents/InspectorCSSAgent.h
Source/WebCore/inspector/agents/InspectorDOMAgent.cpp
Source/WebCore/inspector/agents/InspectorDOMAgent.h
Source/WebCore/inspector/agents/InspectorLayerTreeAgent.cpp
Source/WebCore/inspector/agents/InspectorPageAgent.cpp
Source/WebCore/loader/cache/CachedResourceLoader.cpp
Source/WebCore/platform/graphics/FontGenericFamilies.cpp
Source/WebCore/platform/graphics/ca/GraphicsLayerCA.cpp
Source/WebCore/rendering/RenderThemeMac.mm
Source/WebCore/testing/Internals.cpp
Source/WebCore/xml/parser/XMLDocumentParser.h
Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp