HashMap<>::add should return a more descriptive object

https://bugs.webkit.org/show_bug.cgi?id=71063

Reviewed by Ryosuke Niwa.

Source/JavaScriptCore:

Update code to use AddResult instead of a pair. Note that since WeakGCMap wraps
the iterator type, there's a need for its own AddResult type -- instantiated from
HashTableAddResult template class.

* API/JSCallbackObject.h:
(JSC::JSCallbackObjectData::JSPrivatePropertyMap::setPrivateProperty):
* API/JSClassRef.cpp:
(OpaqueJSClass::contextData):
* bytecompiler/BytecodeGenerator.cpp:
(JSC::BytecodeGenerator::addVar):
(JSC::BytecodeGenerator::addGlobalVar):
(JSC::BytecodeGenerator::addConstant):
(JSC::BytecodeGenerator::addConstantValue):
(JSC::BytecodeGenerator::emitLoad):
(JSC::BytecodeGenerator::addStringConstant):
(JSC::BytecodeGenerator::emitLazyNewFunction):
* bytecompiler/NodesCodegen.cpp:
(JSC::PropertyListNode::emitBytecode):
* debugger/Debugger.cpp:
* dfg/DFGAssemblyHelpers.cpp:
(JSC::DFG::AssemblyHelpers::decodedCodeMapFor):
* dfg/DFGByteCodeParser.cpp:
(JSC::DFG::ByteCodeParser::cellConstant):
(JSC::DFG::ByteCodeParser::InlineStackEntry::InlineStackEntry):
* jit/JITStubs.cpp:
(JSC::JITThunks::ctiStub):
(JSC::JITThunks::hostFunctionStub):
* parser/Parser.cpp:
(JSC::::parseStrictObjectLiteral):
* parser/Parser.h:
(JSC::Scope::declareParameter):
* runtime/Identifier.cpp:
(JSC::Identifier::add):
(JSC::Identifier::add8):
(JSC::Identifier::addSlowCase):
* runtime/Identifier.h:
(JSC::Identifier::add):
(JSC::IdentifierTable::add):
* runtime/JSArray.cpp:
(JSC::SparseArrayValueMap::add):
(JSC::SparseArrayValueMap::put):
(JSC::SparseArrayValueMap::putDirect):
(JSC::JSArray::enterDictionaryMode):
(JSC::JSArray::defineOwnNumericProperty):
* runtime/JSArray.h:
(SparseArrayValueMap):
* runtime/PropertyNameArray.cpp:
(JSC::PropertyNameArray::add):
* runtime/StringRecursionChecker.h:
(JSC::StringRecursionChecker::performCheck):
* runtime/Structure.cpp:
(JSC::StructureTransitionTable::add):
* runtime/WeakGCMap.h:
(WeakGCMap):
(JSC::WeakGCMap::add):
(JSC::WeakGCMap::set):
* tools/ProfileTreeNode.h:
(JSC::ProfileTreeNode::sampleChild):

Source/WebCore:

Update code to use AddResult instead of a pair. No new tests, just a refactoring.

* Modules/webdatabase/SQLTransactionCoordinator.cpp:
(WebCore::SQLTransactionCoordinator::acquireLock):
* Modules/webdatabase/chromium/QuotaTracker.cpp:
(WebCore::QuotaTracker::updateDatabaseSize):
* bindings/js/DOMObjectHashTableMap.h:
(WebCore::DOMObjectHashTableMap::get):
* bindings/js/JSDOMBinding.cpp:
(WebCore::cacheDOMStructure):
* bindings/js/JSDOMBinding.h:
(WebCore::cacheWrapper):
* bindings/js/JSDOMGlobalObject.h:
(WebCore::getDOMConstructor):
* bindings/js/PageScriptDebugServer.cpp:
(WebCore::PageScriptDebugServer::addListener):
* bindings/js/ScriptDebugServer.cpp:
(WebCore::ScriptDebugServer::setBreakpoint):
* bindings/js/SerializedScriptValue.cpp:
(WebCore::CloneSerializer::startObjectInternal):
(WebCore::CloneSerializer::write):
* bindings/v8/NPV8Object.cpp:
(WebCore::npCreateV8ScriptObject):
* bridge/IdentifierRep.cpp:
(WebCore::IdentifierRep::get):
* bridge/NP_jsobject.cpp:
(ObjectMap::add):
* css/CSSComputedStyleDeclaration.cpp:
(WebCore::logUnimplementedPropertyID):
* css/CSSFontFaceSource.cpp:
(WebCore::CSSFontFaceSource::getFontData):
* css/CSSFontSelector.cpp:
(WebCore::CSSFontSelector::addFontFaceRule):
(WebCore::CSSFontSelector::getFontData):
* css/CSSSegmentedFontFace.cpp:
(WebCore::CSSSegmentedFontFace::getFontData):
* css/CSSStyleApplyProperty.cpp:
(WebCore::ApplyPropertyCounter::applyInheritValue):
(WebCore::ApplyPropertyCounter::applyValue):
* css/CSSStyleSelector.cpp:
(WebCore::CSSStyleSelector::appendAuthorStylesheets):
(WebCore::CSSStyleSelector::collectMatchingRulesForList):
* css/CSSValuePool.cpp:
(WebCore::CSSValuePool::createIdentifierValue):
(WebCore::CSSValuePool::createColorValue):
(WebCore::CSSValuePool::createValue):
(WebCore::CSSValuePool::createFontFamilyValue):
(WebCore::CSSValuePool::createFontFaceValue):
* dom/CheckedRadioButtons.cpp:
(WebCore::RadioButtonGroup::add):
(WebCore::CheckedRadioButtons::addButton):
* dom/ChildListMutationScope.cpp:
(WebCore::ChildListMutationScope::MutationAccumulationRouter::incrementScopingLevel):
* dom/Document.cpp:
(WebCore::Document::windowNamedItems):
(WebCore::Document::documentNamedItems):
(WebCore::Document::getCSSCanvasElement):
(WebCore::Document::getItems):
* dom/DocumentEventQueue.cpp:
(WebCore::DocumentEventQueue::enqueueEvent):
(WebCore::DocumentEventQueue::enqueueOrDispatchScrollEvent):
(WebCore::DocumentEventQueue::pendingEventTimerFired):
* dom/DocumentOrderedMap.cpp:
(WebCore::DocumentOrderedMap::add):
* dom/EventListenerMap.cpp:
(WebCore::EventListenerMap::add):
* dom/Node.cpp:
(WebCore::Node::dumpStatistics):
(WebCore::Node::getElementsByTagName):
(WebCore::Node::getElementsByTagNameNS):
(WebCore::Node::getElementsByName):
(WebCore::Node::getElementsByClassName):
(WebCore::Node::collectMatchingObserversForMutation):
* dom/QualifiedName.cpp:
(WebCore::QualifiedName::init):
* dom/SpaceSplitString.cpp:
(WebCore::SpaceSplitStringData::create):
* dom/StyledElement.cpp:
(WebCore::StyledElement::updateAttributeStyle):
* html/HTMLCollection.cpp:
(WebCore::HTMLCollection::append):
* inspector/DOMPatchSupport.cpp:
(WebCore::DOMPatchSupport::diff):
* inspector/InspectorCSSAgent.cpp:
(WebCore::SelectorProfile::commitSelector):
* inspector/InspectorDOMAgent.cpp:
(WebCore::InspectorDOMAgent::performSearch):
* inspector/InspectorDebuggerAgent.cpp:
(WebCore::InspectorDebuggerAgent::resolveBreakpoint):
* inspector/InspectorValues.h:
(WebCore::InspectorObject::setValue):
(WebCore::InspectorObject::setObject):
(WebCore::InspectorObject::setArray):
* loader/appcache/ApplicationCacheGroup.cpp:
(WebCore::ApplicationCacheGroup::addEntry):
* loader/appcache/ApplicationCacheStorage.cpp:
(WebCore::ApplicationCacheStorage::findOrCreateCacheGroup):
* page/EventHandler.cpp:
(WebCore::EventHandler::handleTouchEvent):
* page/PageGroup.cpp:
(WebCore::PageGroup::pageGroup):
(WebCore::PageGroup::addVisitedLink):
(WebCore::PageGroup::addUserScriptToWorld):
(WebCore::PageGroup::addUserStyleSheetToWorld):
* page/SecurityPolicy.cpp:
(WebCore::SecurityPolicy::addOriginAccessWhitelistEntry):
* page/TouchAdjustment.cpp:
(WebCore::TouchAdjustment::compileSubtargetList):
* platform/cf/BinaryPropertyList.cpp:
(WebCore::BinaryPropertyListPlan::writeInteger):
(WebCore::BinaryPropertyListPlan::writeString):
(WebCore::BinaryPropertyListPlan::writeIntegerArray):
* platform/graphics/blackberry/LayerTiler.cpp:
(WebCore::LayerTiler::addTileJob):
* platform/graphics/ca/GraphicsLayerCA.cpp:
(WebCore::GraphicsLayerCA::findOrMakeClone):
* platform/graphics/ca/mac/TileCache.mm:
(WebCore::TileCache::revalidateTiles):
* platform/graphics/ca/win/LayerChangesFlusher.cpp:
(WebCore::LayerChangesFlusher::flushPendingLayerChangesSoon):
* platform/graphics/chromium/FontUtilsChromiumWin.cpp:
(WebCore::getDerivedFontData):
* platform/graphics/chromium/cc/CCLayerAnimationController.cpp:
(WebCore::CCLayerAnimationController::startAnimationsWaitingForTargetAvailability):
* platform/graphics/mac/ComplexTextControllerATSUI.cpp:
(WebCore::initializeATSUStyle):
* platform/graphics/mac/SimpleFontDataCoreText.cpp:
(WebCore::SimpleFontData::getCFStringAttributes):
* platform/graphics/mac/SimpleFontDataMac.mm:
(WebCore::SimpleFontData::canRenderCombiningCharacterSequence):
* platform/graphics/wince/FontPlatformData.cpp:
(WebCore::FixedSizeFontData::create):
* platform/gtk/RenderThemeGtk3.cpp:
(WebCore::getStyleContext):
* platform/mac/ThreadCheck.mm:
(WebCoreReportThreadViolation):
* platform/network/HTTPHeaderMap.cpp:
(WebCore::HTTPHeaderMap::add):
* platform/network/HTTPHeaderMap.h:
(HTTPHeaderMap):
* platform/network/ResourceRequestBase.cpp:
(WebCore::ResourceRequestBase::addHTTPHeaderField):
* plugins/PluginDatabase.cpp:
(WebCore::PluginDatabase::add):
(WebCore::PluginDatabase::loadPersistentMetadataCache):
* plugins/win/PluginDatabaseWin.cpp:
(WebCore::PluginDatabase::getPluginPathsInDirectories):
* rendering/RenderBlock.cpp:
(WebCore::RenderBlock::addPercentHeightDescendant):
* rendering/RenderBlockLineLayout.cpp:
(WebCore::setLogicalWidthForTextRun):
* rendering/RenderNamedFlowThread.cpp:
(WebCore::RenderNamedFlowThread::addDependencyOnFlowThread):
* rendering/RenderRegion.cpp:
(WebCore::RenderRegion::setRenderBoxRegionInfo):
* rendering/svg/RenderSVGResourceGradient.cpp:
(WebCore::RenderSVGResourceGradient::applyResource):
* rendering/svg/RenderSVGResourcePattern.cpp:
(WebCore::RenderSVGResourcePattern::applyResource):
* storage/StorageMap.cpp:
(WebCore::StorageMap::setItem):
(WebCore::StorageMap::importItem):
* svg/SVGDocumentExtensions.cpp:
(WebCore::SVGDocumentExtensions::addPendingResource):
* xml/XMLHttpRequest.cpp:
(WebCore::XMLHttpRequest::setRequestHeaderInternal):
* xml/XPathFunctions.cpp:
(WebCore::XPath::FunId::evaluate):
* xml/XPathPath.cpp:
(WebCore::XPath::LocationPath::evaluate):
* xml/XPathPredicate.cpp:
(WebCore::XPath::Union::evaluate):

Source/WebKit/chromium:

Update code to use AddResult instead of a pair.

* src/WebHTTPLoadInfo.cpp:
(WebKit::addHeader):
* src/WebURLResponse.cpp:
(WebKit::WebURLResponse::addHTTPHeaderField):

Source/WebKit/mac:

Update code to use AddResult instead of a pair.

* Plugins/Hosted/NetscapePluginHostManager.mm:
(WebKit::NetscapePluginHostManager::hostForPlugin):
* Plugins/Hosted/ProxyInstance.mm:
(WebKit::ProxyInstance::methodsNamed):
(WebKit::ProxyInstance::fieldNamed):
* WebCoreSupport/WebNotificationClient.mm:
(WebNotificationClient::show):

Source/WebKit/win:

Update code to use AddResult instead of a pair.

* WebKitCOMAPI.cpp:
(classFactory):

Source/WebKit2:

Update code to use AddResult instead of a pair.

* Platform/CoreIPC/ArgumentCoders.h:
* Platform/CoreIPC/Connection.cpp:
(CoreIPC::Connection::SyncMessageState::getOrCreate):
* Shared/MutableDictionary.cpp:
(WebKit::MutableDictionary::add):
(WebKit::MutableDictionary::set):
* Shared/UserMessageCoders.h:
(WebKit::UserMessageDecoder::baseDecode):
* Shared/mac/CommandLineMac.cpp:
(WebKit::CommandLine::parse):
* UIProcess/API/mac/WKPrintingView.mm:
(pageDidDrawToPDF):
* UIProcess/API/mac/WKView.mm:
(-[WKView validateUserInterfaceItem:]):
* UIProcess/WebProcessProxy.cpp:
(WebKit::WebProcessProxy::addBackForwardItem):
* WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.cpp:
(WebKit::InjectedBundleNodeHandle::getOrCreate):
* WebProcess/InjectedBundle/DOM/InjectedBundleRangeHandle.cpp:
(WebKit::InjectedBundleRangeHandle::getOrCreate):
* WebProcess/Notifications/WebNotificationManager.cpp:
(WebKit::WebNotificationManager::show):
* WebProcess/WebProcess.cpp:
(WebKit::WebProcess::createWebPage):
(WebKit::WebProcess::webPageGroup):

Source/WTF:

Make HashTable<>::add() and derivate functions return an AddResult struct instead
of a pair. This struct contains contains 'iterator' and 'isNewEntry' members, that are
more readable at callsites than previous 'first' and 'second'.

* wtf/HashCountedSet.h:
(HashCountedSet):
(WTF::::add):
* wtf/HashMap.h:
(HashMap):
(WTF):
(WTF::::set):
* wtf/HashSet.h:
(HashSet):
(WTF::::add):
(WTF):
* wtf/HashTable.h:
(WTF::HashTableAddResult::HashTableAddResult):
(HashTableAddResult):
(WTF):
(HashTable):
(WTF::HashTable::add):
(WTF::::add):
(WTF::::addPassingHashCode):
* wtf/ListHashSet.h:
(ListHashSet):
(WTF::::add):
(WTF::::insertBefore):
* wtf/RefPtrHashMap.h:
(WTF):
(WTF::::set):
* wtf/Spectrum.h:
(WTF::Spectrum::add):
* wtf/WTFThreadData.cpp:
(JSC::IdentifierTable::add):
* wtf/WTFThreadData.h:
(IdentifierTable):
* wtf/text/AtomicString.cpp:
(WTF::addToStringTable):
(WTF::AtomicString::addSlowCase):

Tools:

Update code to use AddResult instead of a pair.

* DumpRenderTree/mac/LayoutTestControllerMac.mm:
(LayoutTestController::evaluateScriptInIsolatedWorld):
* DumpRenderTree/win/LayoutTestControllerWin.cpp:
(LayoutTestController::evaluateScriptInIsolatedWorld):
* WebKitTestRunner/InjectedBundle/LayoutTestController.cpp:
(WTR::LayoutTestController::evaluateScriptInIsolatedWorld):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@112555 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 207da1c2
......@@ -89,7 +89,7 @@ struct JSCallbackObjectData : WeakHandleOwner {
void setPrivateProperty(JSGlobalData& globalData, JSCell* owner, const Identifier& propertyName, JSValue value)
{
WriteBarrier<Unknown> empty;
m_propertyMap.add(propertyName.impl(), empty).first->second.set(globalData, owner, value);
m_propertyMap.add(propertyName.impl(), empty).iterator->second.set(globalData, owner, value);
}
void deletePrivateProperty(const Identifier& propertyName)
......
......@@ -164,7 +164,7 @@ OpaqueJSClassContextData::OpaqueJSClassContextData(JSC::JSGlobalData&, OpaqueJSC
OpaqueJSClassContextData& OpaqueJSClass::contextData(ExecState* exec)
{
OwnPtr<OpaqueJSClassContextData>& contextData = exec->globalData().opaqueJSClassData.add(this, nullptr).first->second;
OwnPtr<OpaqueJSClassContextData>& contextData = exec->globalData().opaqueJSClassData.add(this, nullptr).iterator->second;
if (!contextData)
contextData = adoptPtr(new OpaqueJSClassContextData(exec->globalData(), this));
return *contextData;
......
2012-03-29 Caio Marcelo de Oliveira Filho <caio.oliveira@openbossa.org>
HashMap<>::add should return a more descriptive object
https://bugs.webkit.org/show_bug.cgi?id=71063
Reviewed by Ryosuke Niwa.
Update code to use AddResult instead of a pair. Note that since WeakGCMap wraps
the iterator type, there's a need for its own AddResult type -- instantiated from
HashTableAddResult template class.
* API/JSCallbackObject.h:
(JSC::JSCallbackObjectData::JSPrivatePropertyMap::setPrivateProperty):
* API/JSClassRef.cpp:
(OpaqueJSClass::contextData):
* bytecompiler/BytecodeGenerator.cpp:
(JSC::BytecodeGenerator::addVar):
(JSC::BytecodeGenerator::addGlobalVar):
(JSC::BytecodeGenerator::addConstant):
(JSC::BytecodeGenerator::addConstantValue):
(JSC::BytecodeGenerator::emitLoad):
(JSC::BytecodeGenerator::addStringConstant):
(JSC::BytecodeGenerator::emitLazyNewFunction):
* bytecompiler/NodesCodegen.cpp:
(JSC::PropertyListNode::emitBytecode):
* debugger/Debugger.cpp:
* dfg/DFGAssemblyHelpers.cpp:
(JSC::DFG::AssemblyHelpers::decodedCodeMapFor):
* dfg/DFGByteCodeParser.cpp:
(JSC::DFG::ByteCodeParser::cellConstant):
(JSC::DFG::ByteCodeParser::InlineStackEntry::InlineStackEntry):
* jit/JITStubs.cpp:
(JSC::JITThunks::ctiStub):
(JSC::JITThunks::hostFunctionStub):
* parser/Parser.cpp:
(JSC::::parseStrictObjectLiteral):
* parser/Parser.h:
(JSC::Scope::declareParameter):
* runtime/Identifier.cpp:
(JSC::Identifier::add):
(JSC::Identifier::add8):
(JSC::Identifier::addSlowCase):
* runtime/Identifier.h:
(JSC::Identifier::add):
(JSC::IdentifierTable::add):
* runtime/JSArray.cpp:
(JSC::SparseArrayValueMap::add):
(JSC::SparseArrayValueMap::put):
(JSC::SparseArrayValueMap::putDirect):
(JSC::JSArray::enterDictionaryMode):
(JSC::JSArray::defineOwnNumericProperty):
* runtime/JSArray.h:
(SparseArrayValueMap):
* runtime/PropertyNameArray.cpp:
(JSC::PropertyNameArray::add):
* runtime/StringRecursionChecker.h:
(JSC::StringRecursionChecker::performCheck):
* runtime/Structure.cpp:
(JSC::StructureTransitionTable::add):
* runtime/WeakGCMap.h:
(WeakGCMap):
(JSC::WeakGCMap::add):
(JSC::WeakGCMap::set):
* tools/ProfileTreeNode.h:
(JSC::ProfileTreeNode::sampleChild):
2012-03-29 Patrick Gansterer <paroga@webkit.org>
Build fix for !ENABLE(YARR_JIT) after r112454.
......@@ -200,10 +200,10 @@ bool BytecodeGenerator::addVar(const Identifier& ident, bool isConstant, Registe
{
int index = m_calleeRegisters.size();
SymbolTableEntry newEntry(index, isConstant ? ReadOnly : 0);
pair<SymbolTable::iterator, bool> result = symbolTable().add(ident.impl(), newEntry);
SymbolTable::AddResult result = symbolTable().add(ident.impl(), newEntry);
if (!result.second) {
r0 = &registerFor(result.first->second.getIndex());
if (!result.isNewEntry) {
r0 = &registerFor(result.iterator->second.getIndex());
return false;
}
......@@ -215,9 +215,9 @@ int BytecodeGenerator::addGlobalVar(const Identifier& ident, bool isConstant)
{
int index = symbolTable().size();
SymbolTableEntry newEntry(index, isConstant ? ReadOnly : 0);
pair<SymbolTable::iterator, bool> result = symbolTable().add(ident.impl(), newEntry);
if (!result.second)
index = result.first->second.getIndex();
SymbolTable::AddResult result = symbolTable().add(ident.impl(), newEntry);
if (!result.isNewEntry)
index = result.iterator->second.getIndex();
return index;
}
......@@ -968,24 +968,24 @@ PassRefPtr<Label> BytecodeGenerator::emitJumpIfNotFunctionApply(RegisterID* cond
unsigned BytecodeGenerator::addConstant(const Identifier& ident)
{
StringImpl* rep = ident.impl();
pair<IdentifierMap::iterator, bool> result = m_identifierMap.add(rep, m_codeBlock->numberOfIdentifiers());
if (result.second) // new entry
IdentifierMap::AddResult result = m_identifierMap.add(rep, m_codeBlock->numberOfIdentifiers());
if (result.isNewEntry)
m_codeBlock->addIdentifier(Identifier(m_globalData, rep));
return result.first->second;
return result.iterator->second;
}
RegisterID* BytecodeGenerator::addConstantValue(JSValue v)
{
int index = m_nextConstantOffset;
pair<JSValueMap::iterator, bool> result = m_jsValueMap.add(JSValue::encode(v), m_nextConstantOffset);
if (result.second) {
JSValueMap::AddResult result = m_jsValueMap.add(JSValue::encode(v), m_nextConstantOffset);
if (result.isNewEntry) {
m_constantPoolRegisters.append(FirstConstantRegisterIndex + m_nextConstantOffset);
++m_nextConstantOffset;
m_codeBlock->addConstant(JSValue(v));
} else
index = result.first->second;
index = result.iterator->second;
return &m_constantPoolRegisters[index];
}
......@@ -1132,7 +1132,7 @@ RegisterID* BytecodeGenerator::emitLoad(RegisterID* dst, double number)
// work correctly with NaN as a key.
if (isnan(number) || number == HashTraits<double>::emptyValue() || HashTraits<double>::isDeletedValue(number))
return emitLoad(dst, jsNumber(number));
JSValue& valueInMap = m_numberMap.add(number, JSValue()).first->second;
JSValue& valueInMap = m_numberMap.add(number, JSValue()).iterator->second;
if (!valueInMap)
valueInMap = jsNumber(number);
return emitLoad(dst, valueInMap);
......@@ -1140,7 +1140,7 @@ RegisterID* BytecodeGenerator::emitLoad(RegisterID* dst, double number)
RegisterID* BytecodeGenerator::emitLoad(RegisterID* dst, const Identifier& identifier)
{
JSString*& stringInMap = m_stringMap.add(identifier.impl(), 0).first->second;
JSString*& stringInMap = m_stringMap.add(identifier.impl(), 0).iterator->second;
if (!stringInMap)
stringInMap = jsOwnedString(globalData(), identifier.ustring());
return emitLoad(dst, JSValue(stringInMap));
......@@ -1648,7 +1648,7 @@ unsigned BytecodeGenerator::addConstantBuffer(unsigned length)
JSString* BytecodeGenerator::addStringConstant(const Identifier& identifier)
{
JSString*& stringInMap = m_stringMap.add(identifier.impl(), 0).first->second;
JSString*& stringInMap = m_stringMap.add(identifier.impl(), 0).iterator->second;
if (!stringInMap) {
stringInMap = jsString(globalData(), identifier.ustring());
addConstantValue(stringInMap);
......@@ -1718,10 +1718,10 @@ RegisterID* BytecodeGenerator::emitNewFunction(RegisterID* dst, FunctionBodyNode
RegisterID* BytecodeGenerator::emitLazyNewFunction(RegisterID* dst, FunctionBodyNode* function)
{
std::pair<FunctionOffsetMap::iterator, bool> ptr = m_functionOffsets.add(function, 0);
if (ptr.second)
ptr.first->second = m_codeBlock->addFunctionDecl(makeFunction(m_globalData, function));
return emitNewFunctionInternal(dst, ptr.first->second, true);
FunctionOffsetMap::AddResult ptr = m_functionOffsets.add(function, 0);
if (ptr.isNewEntry)
ptr.iterator->second = m_codeBlock->addFunctionDecl(makeFunction(m_globalData, function));
return emitNewFunctionInternal(dst, ptr.iterator->second, true);
}
RegisterID* BytecodeGenerator::emitNewFunctionInternal(RegisterID* dst, unsigned index, bool doNullCheck)
......
......@@ -256,9 +256,9 @@ RegisterID* PropertyListNode::emitBytecode(BytecodeGenerator& generator, Registe
continue;
GetterSetterPair pair(node, static_cast<PropertyNode*>(0));
std::pair<GetterSetterMap::iterator, bool> result = map.add(node->name().impl(), pair);
if (!result.second)
result.first->second.second = node;
GetterSetterMap::AddResult result = map.add(node->name().impl(), pair);
if (!result.isNewEntry)
result.iterator->second.second = node;
}
// Iterate over the remaining properties in the list.
......
......@@ -75,7 +75,7 @@ inline void Recompiler::operator()(JSCell* cell)
// Check if the function is already in the set - if so,
// we've already retranslated it, nothing to do here.
if (!m_functionExecutables.add(executable).second)
if (!m_functionExecutables.add(executable).isNewEntry)
return;
ExecState* exec = function->scope()->globalObject->JSGlobalObject::globalExec();
......
......@@ -38,12 +38,12 @@ Vector<BytecodeAndMachineOffset>& AssemblyHelpers::decodedCodeMapFor(CodeBlock*
ASSERT(codeBlock->getJITType() == JITCode::BaselineJIT);
ASSERT(codeBlock->jitCodeMap());
std::pair<HashMap<CodeBlock*, Vector<BytecodeAndMachineOffset> >::iterator, bool> result = m_decodedCodeMaps.add(codeBlock, Vector<BytecodeAndMachineOffset>());
HashMap<CodeBlock*, Vector<BytecodeAndMachineOffset> >::AddResult result = m_decodedCodeMaps.add(codeBlock, Vector<BytecodeAndMachineOffset>());
if (result.second)
codeBlock->jitCodeMap()->decode(result.first->second);
if (result.isNewEntry)
codeBlock->jitCodeMap()->decode(result.iterator->second);
return result.first->second;
return result.iterator->second;
}
#if ENABLE(SAMPLING_FLAGS)
......
......@@ -551,11 +551,11 @@ private:
NodeIndex cellConstant(JSCell* cell)
{
pair<HashMap<JSCell*, NodeIndex>::iterator, bool> iter = m_cellConstantNodes.add(cell, NoNode);
if (iter.second)
iter.first->second = addToGraph(WeakJSConstant, OpInfo(cell));
HashMap<JSCell*, NodeIndex>::AddResult result = m_cellConstantNodes.add(cell, NoNode);
if (result.isNewEntry)
result.iterator->second = addToGraph(WeakJSConstant, OpInfo(cell));
return iter.first->second;
return result.iterator->second;
}
CodeOrigin currentCodeOrigin()
......@@ -2595,10 +2595,10 @@ ByteCodeParser::InlineStackEntry::InlineStackEntry(ByteCodeParser* byteCodeParse
for (size_t i = 0; i < codeBlock->numberOfIdentifiers(); ++i) {
StringImpl* rep = codeBlock->identifier(i).impl();
pair<IdentifierMap::iterator, bool> result = byteCodeParser->m_identifierMap.add(rep, byteCodeParser->m_codeBlock->numberOfIdentifiers());
if (result.second)
IdentifierMap::AddResult result = byteCodeParser->m_identifierMap.add(rep, byteCodeParser->m_codeBlock->numberOfIdentifiers());
if (result.isNewEntry)
byteCodeParser->m_codeBlock->addIdentifier(Identifier(byteCodeParser->m_globalData, rep));
m_identifierRemap[i] = result.first->second;
m_identifierRemap[i] = result.iterator->second;
}
for (size_t i = 0; i < codeBlock->numberOfConstantRegisters(); ++i) {
JSValue value = codeBlock->getConstant(i + FirstConstantRegisterIndex);
......@@ -2611,12 +2611,12 @@ ByteCodeParser::InlineStackEntry::InlineStackEntry(ByteCodeParser* byteCodeParse
m_constantRemap[i] = byteCodeParser->m_emptyJSValueIndex;
continue;
}
pair<JSValueMap::iterator, bool> result = byteCodeParser->m_jsValueMap.add(JSValue::encode(value), byteCodeParser->m_codeBlock->numberOfConstantRegisters() + FirstConstantRegisterIndex);
if (result.second) {
JSValueMap::AddResult result = byteCodeParser->m_jsValueMap.add(JSValue::encode(value), byteCodeParser->m_codeBlock->numberOfConstantRegisters() + FirstConstantRegisterIndex);
if (result.isNewEntry) {
byteCodeParser->m_codeBlock->addConstant(value);
byteCodeParser->m_constants.append(ConstantRecord());
}
m_constantRemap[i] = result.first->second;
m_constantRemap[i] = result.iterator->second;
}
m_callsiteBlockHeadNeedsLinking = true;
......
......@@ -3558,24 +3558,24 @@ DEFINE_STUB_FUNCTION(EncodedJSValue, to_object)
MacroAssemblerCodeRef JITThunks::ctiStub(JSGlobalData* globalData, ThunkGenerator generator)
{
std::pair<CTIStubMap::iterator, bool> entry = m_ctiStubMap.add(generator, MacroAssemblerCodeRef());
if (entry.second)
entry.first->second = generator(globalData);
return entry.first->second;
CTIStubMap::AddResult entry = m_ctiStubMap.add(generator, MacroAssemblerCodeRef());
if (entry.isNewEntry)
entry.iterator->second = generator(globalData);
return entry.iterator->second;
}
NativeExecutable* JITThunks::hostFunctionStub(JSGlobalData* globalData, NativeFunction function, NativeFunction constructor)
{
std::pair<HostFunctionStubMap::iterator, bool> result = m_hostFunctionStubMap->add(function, PassWeak<NativeExecutable>());
if (!result.first->second)
result.first->second = PassWeak<NativeExecutable>(*globalData, NativeExecutable::create(*globalData, JIT::compileCTINativeCall(globalData, function), function, MacroAssemblerCodeRef::createSelfManagedCodeRef(ctiNativeConstruct()), constructor, NoIntrinsic));
return result.first->second.get();
HostFunctionStubMap::AddResult result = m_hostFunctionStubMap->add(function, PassWeak<NativeExecutable>());
if (!result.iterator->second)
result.iterator->second = PassWeak<NativeExecutable>(*globalData, NativeExecutable::create(*globalData, JIT::compileCTINativeCall(globalData, function), function, MacroAssemblerCodeRef::createSelfManagedCodeRef(ctiNativeConstruct()), constructor, NoIntrinsic));
return result.iterator->second.get();
}
NativeExecutable* JITThunks::hostFunctionStub(JSGlobalData* globalData, NativeFunction function, ThunkGenerator generator, Intrinsic intrinsic)
{
std::pair<HostFunctionStubMap::iterator, bool> entry = m_hostFunctionStubMap->add(function, PassWeak<NativeExecutable>());
if (!*entry.first->second) {
HostFunctionStubMap::AddResult entry = m_hostFunctionStubMap->add(function, PassWeak<NativeExecutable>());
if (!*entry.iterator->second) {
MacroAssemblerCodeRef code;
if (generator) {
if (globalData->canUseJIT())
......@@ -3584,9 +3584,9 @@ NativeExecutable* JITThunks::hostFunctionStub(JSGlobalData* globalData, NativeFu
code = MacroAssemblerCodeRef();
} else
code = JIT::compileCTINativeCall(globalData, function);
entry.first->second = PassWeak<NativeExecutable>(*globalData, NativeExecutable::create(*globalData, code, function, MacroAssemblerCodeRef::createSelfManagedCodeRef(ctiNativeConstruct()), callHostFunctionAsConstructor, intrinsic));
entry.iterator->second = PassWeak<NativeExecutable>(*globalData, NativeExecutable::create(*globalData, code, function, MacroAssemblerCodeRef::createSelfManagedCodeRef(ctiNativeConstruct()), callHostFunctionAsConstructor, intrinsic));
}
return entry.first->second.get();
return entry.iterator->second.get();
}
void JITThunks::clearHostFunctionStubs()
......
......@@ -1323,12 +1323,12 @@ template <class TreeBuilder> TreeExpression Parser<LexerType>::parseStrictObject
property = parseProperty<true>(context);
failIfFalse(property);
if (!m_syntaxAlreadyValidated) {
std::pair<ObjectValidationMap::iterator, bool> propertyEntryIter = objectValidator.add(context.getName(property).impl(), context.getType(property));
if (!propertyEntryIter.second) {
failIfTrue(propertyEntryIter.first->second == PropertyNode::Constant);
ObjectValidationMap::AddResult propertyEntry = objectValidator.add(context.getName(property).impl(), context.getType(property));
if (!propertyEntry.isNewEntry) {
failIfTrue(propertyEntry.iterator->second == PropertyNode::Constant);
failIfTrue(context.getType(property) == PropertyNode::Constant);
failIfTrue(context.getType(property) & propertyEntryIter.first->second);
propertyEntryIter.first->second |= context.getType(property);
failIfTrue(context.getType(property) & propertyEntry.iterator->second);
propertyEntry.iterator->second |= context.getType(property);
}
}
tail = context.createPropertyList(m_lexer->lastLineNumber(), property, tail);
......
......@@ -223,7 +223,7 @@ struct Scope {
bool declareParameter(const Identifier* ident)
{
bool isArguments = m_globalData->propertyNames->arguments == *ident;
bool isValidStrictMode = m_declaredVariables.add(ident->ustring().impl()).second && m_globalData->propertyNames->eval != *ident && !isArguments;
bool isValidStrictMode = m_declaredVariables.add(ident->ustring().impl()).isNewEntry && m_globalData->propertyNames->eval != *ident && !isArguments;
m_isValidStrictMode = m_isValidStrictMode && isValidStrictMode;
if (isArguments)
setFlags(ShadowsArgumentsFlag);
......
......@@ -110,11 +110,11 @@ PassRefPtr<StringImpl> Identifier::add(JSGlobalData* globalData, const char* c)
if (iter != literalIdentifierTable.end())
return iter->second;
pair<HashSet<StringImpl*>::iterator, bool> addResult = identifierTable.add<const LChar*, IdentifierCStringTranslator>(reinterpret_cast<const LChar*>(c));
HashSet<StringImpl*>::AddResult addResult = identifierTable.add<const LChar*, IdentifierCStringTranslator>(reinterpret_cast<const LChar*>(c));
// If the string is newly-translated, then we need to adopt it.
// The boolean in the pair tells us if that is so.
RefPtr<StringImpl> addedString = addResult.second ? adoptRef(*addResult.first) : *addResult.first;
RefPtr<StringImpl> addedString = addResult.isNewEntry ? adoptRef(*addResult.iterator) : *addResult.iterator;
literalIdentifierTable.add(c, addedString.get());
......@@ -138,11 +138,11 @@ PassRefPtr<StringImpl> Identifier::add8(JSGlobalData* globalData, const UChar* s
if (!length)
return StringImpl::empty();
CharBuffer<UChar> buf = {s, length};
pair<HashSet<StringImpl*>::iterator, bool> addResult = globalData->identifierTable->add<CharBuffer<UChar>, IdentifierLCharFromUCharTranslator >(buf);
HashSet<StringImpl*>::AddResult addResult = globalData->identifierTable->add<CharBuffer<UChar>, IdentifierLCharFromUCharTranslator >(buf);
// If the string is newly-translated, then we need to adopt it.
// The boolean in the pair tells us if that is so.
return addResult.second ? adoptRef(*addResult.first) : *addResult.first;
return addResult.isNewEntry ? adoptRef(*addResult.iterator) : *addResult.iterator;
}
template <typename CharType>
......@@ -210,7 +210,7 @@ PassRefPtr<StringImpl> Identifier::addSlowCase(JSGlobalData* globalData, StringI
return r;
}
return *globalData->identifierTable->add(r).first;
return *globalData->identifierTable->add(r).iterator;
}
PassRefPtr<StringImpl> Identifier::addSlowCase(ExecState* exec, StringImpl* r)
......
......@@ -178,11 +178,11 @@ namespace JSC {
if (!length)
return StringImpl::empty();
CharBuffer<T> buf = {s, length};
pair<HashSet<StringImpl*>::iterator, bool> addResult = globalData->identifierTable->add<CharBuffer<T>, IdentifierCharBufferTranslator<T> >(buf);
HashSet<StringImpl*>::AddResult addResult = globalData->identifierTable->add<CharBuffer<T>, IdentifierCharBufferTranslator<T> >(buf);
// If the string is newly-translated, then we need to adopt it.
// The boolean in the pair tells us if that is so.
return addResult.second ? adoptRef(*addResult.first) : *addResult.first;
return addResult.isNewEntry ? adoptRef(*addResult.iterator) : *addResult.iterator;
}
inline bool operator==(const Identifier& a, const Identifier& b)
......@@ -246,10 +246,10 @@ namespace JSC {
typedef HashMap<RefPtr<StringImpl>, int, IdentifierRepHash, HashTraits<RefPtr<StringImpl> >, IdentifierMapIndexHashTraits> IdentifierMap;
template<typename U, typename V>
std::pair<HashSet<StringImpl*>::iterator, bool> IdentifierTable::add(U value)
HashSet<StringImpl*>::AddResult IdentifierTable::add(U value)
{
std::pair<HashSet<StringImpl*>::iterator, bool> result = m_table.add<U, V>(value);
(*result.first)->setIsIdentifier(true);
HashSet<StringImpl*>::AddResult result = m_table.add<U, V>(value);
(*result.iterator)->setIsIdentifier(true);
return result;
}
......
......@@ -195,10 +195,10 @@ void JSArray::finalize(JSCell* cell)
thisObject->deallocateSparseMap();
}
inline std::pair<SparseArrayValueMap::iterator, bool> SparseArrayValueMap::add(JSArray* array, unsigned i)
inline SparseArrayValueMap::AddResult SparseArrayValueMap::add(JSArray* array, unsigned i)
{
SparseArrayEntry entry;
std::pair<iterator, bool> result = m_map.add(i, entry);
AddResult result = m_map.add(i, entry);
size_t capacity = m_map.capacity();
if (capacity != m_reportedCapacity) {
Heap::heap(array)->reportExtraMemoryCost((capacity - m_reportedCapacity) * (sizeof(unsigned) + sizeof(WriteBarrier<Unknown>)));
......@@ -209,14 +209,14 @@ inline std::pair<SparseArrayValueMap::iterator, bool> SparseArrayValueMap::add(J
inline void SparseArrayValueMap::put(ExecState* exec, JSArray* array, unsigned i, JSValue value, bool shouldThrow)
{
std::pair<SparseArrayValueMap::iterator, bool> result = add(array, i);
SparseArrayEntry& entry = result.first->second;
AddResult result = add(array, i);
SparseArrayEntry& entry = result.iterator->second;
// To save a separate find & add, we first always add to the sparse map.
// In the uncommon case that this is a new property, and the array is not
// extensible, this is not the right thing to have done - so remove again.
if (result.second && !array->isExtensible()) {
remove(result.first);
if (result.isNewEntry && !array->isExtensible()) {
remove(result.iterator);
if (shouldThrow)
throwTypeError(exec, StrictModeReadonlyPropertyWriteError);
return;
......@@ -252,14 +252,14 @@ inline void SparseArrayValueMap::put(ExecState* exec, JSArray* array, unsigned i
inline bool SparseArrayValueMap::putDirect(ExecState* exec, JSArray* array, unsigned i, JSValue value, bool shouldThrow)
{
std::pair<SparseArrayValueMap::iterator, bool> result = add(array, i);
SparseArrayEntry& entry = result.first->second;
AddResult result = add(array, i);
SparseArrayEntry& entry = result.iterator->second;
// To save a separate find & add, we first always add to the sparse map.
// In the uncommon case that this is a new property, and the array is not
// extensible, this is not the right thing to have done - so remove again.
if (result.second && !array->isExtensible()) {
remove(result.first);
if (result.isNewEntry && !array->isExtensible()) {
remove(result.iterator);
return reject(exec, shouldThrow, "Attempting to define property on object that is not extensible.");
}
......@@ -355,7 +355,7 @@ void JSArray::enterDictionaryMode(JSGlobalData& globalData)
// This will always be a new entry in the map, so no need to check we can write,
// and attributes are default so no need to set them.
if (value)
map->add(this, i).first->second.set(globalData, this, value);
map->add(this, i).iterator->second.set(globalData, this, value);
}
void* newRawStorage = 0;
......@@ -430,15 +430,15 @@ bool JSArray::defineOwnNumericProperty(ExecState* exec, unsigned index, Property
ASSERT(map);
// 1. Let current be the result of calling the [[GetOwnProperty]] internal method of O with property name P.
std::pair<SparseArrayValueMap::iterator, bool> result = map->add(this, index);
SparseArrayEntry* entryInMap = &result.first->second;
SparseArrayValueMap::AddResult result = map->add(this, index);
SparseArrayEntry* entryInMap = &result.iterator->second;
// 2. Let extensible be the value of the [[Extensible]] internal property of O.
// 3. If current is undefined and extensible is false, then Reject.
// 4. If current is undefined and extensible is true, then
if (result.second) {
if (result.isNewEntry) {
if (!isExtensible()) {
map->remove(result.first);
map->remove(result.iterator);
return reject(exec, throwException, "Attempting to define property on object that is not extensible.");
}
......
......@@ -55,6 +55,7 @@ namespace JSC {
public:
typedef Map::iterator iterator;
typedef Map::const_iterator const_iterator;
typedef Map::AddResult AddResult;
SparseArrayValueMap()
: m_flags(Normal)
......@@ -87,7 +88,7 @@ namespace JSC {
// These methods may mutate the contents of the map
void put(ExecState*, JSArray*, unsigned, JSValue, bool shouldThrow);
bool putDirect(ExecState*, JSArray*, unsigned, JSValue, bool shouldThrow);
std::pair<iterator, bool> add(JSArray*, unsigned);
AddResult add(JSArray*, unsigned);
iterator find(unsigned i) { return m_map.find(i); }
// This should ASSERT the remove is valid (check the result of the find).
void remove(iterator it) { m_map.remove(it); }
......
......@@ -45,7 +45,7 @@ void PropertyNameArray::add(StringImpl* identifier)
for (size_t i = 0; i < size; ++i)
m_set.add(m_data->propertyNameVector()[i].impl());
}
if (!m_set.add(identifier).second)
if (!m_set.add(identifier).isNewEntry)
return;
}
......
......@@ -48,7 +48,7 @@ inline JSValue StringRecursionChecker::performCheck()
int size = m_exec->globalData().stringRecursionCheckVisitedObjects.size();
if (size >= MaxSmallThreadReentryDepth && size >= m_exec->globalData().maxReentryDepth)
return throwStackOverflowError();
bool alreadyVisited = !m_exec->globalData().stringRecursionCheckVisitedObjects.add(m_thisObject).second;
bool alreadyVisited = !m_exec->globalData().stringRecursionCheckVisitedObjects.add(m_thisObject).isNewEntry;
if (alreadyVisited)
return emptyString(); // Return empty string to avoid infinite recursion.
return JSValue(); // Indicate success.
......
......@@ -102,12 +102,12 @@ inline void StructureTransitionTable::add(JSGlobalData& globalData, Structure* s
// Newer versions of the STL have an std::make_pair function that takes rvalue references.
// When either of the parameters are bitfields, the C++ compiler will try to bind them as lvalues, which is invalid. To work around this, use unary "+" to make the parameter an rvalue.
// See https://bugs.webkit.org/show_bug.cgi?id=59261 for more details
std::pair<TransitionMap::iterator, bool> result = map()->add(globalData, make_pair(structure->m_nameInPrevious, +structure->m_attributesInPrevious), structure);
if (!result.second) {
TransitionMap::AddResult result = map()->add(globalData, make_pair(structure->m_nameInPrevious, +structure->m_attributesInPrevious), structure);
if (!result.isNewEntry) {
// There already is an entry! - we should only hit this when despecifying.
ASSERT(result.first.get().second->m_specificValueInPrevious);
ASSERT(result.iterator.get().second->m_specificValueInPrevious);
ASSERT(!structure->m_specificValueInPrevious);
map()->set(result.first, structure);
map()->set(result.iterator, structure);
}
}
......
......@@ -79,6 +79,8 @@ public:
map_iterator m_iterator;
};
typedef WTF::HashTableAddResult<iterator> AddResult;
WeakGCMap()
{
}
......@@ -121,17 +123,18 @@ public:
return m_map.get(key);
}
pair<iterator, bool> add(JSGlobalData& globalData, const KeyType& key, ExternalType value)
AddResult add(JSGlobalData& globalData, const KeyType& key, ExternalType value)