WebCore:
[WebKit-https.git] / WebCore / html / HTMLFormElement.cpp
index 453674360798e09edd04ccbbd2d76528d93d07dd..b2d8fa32d5625a0c7885079f030b882afb6038d7 100644 (file)
@@ -721,21 +721,26 @@ void HTMLFormElement::CheckedRadioButtons::addButton(HTMLGenericFormElement* ele
         return;
 
     HTMLInputElement* inputElement = static_cast<HTMLInputElement*>(element);
+
     // We only track checked buttons.
     if (!inputElement->checked())
         return;
 
     if (!m_nameToCheckedRadioButtonMap)
         m_nameToCheckedRadioButtonMap.set(new NameToInputMap);
-    else {
-        HTMLInputElement* currentCheckedRadio = m_nameToCheckedRadioButtonMap->get(element->name().impl());
-        if (currentCheckedRadio && currentCheckedRadio != element)
-            currentCheckedRadio->setChecked(false);
-    }
 
-    m_nameToCheckedRadioButtonMap->set(element->name().impl(), inputElement);    
-}
+    pair<NameToInputMap::iterator, bool> result = m_nameToCheckedRadioButtonMap->add(element->name().impl(), inputElement);
+    if (result.second)
+        return;
     
+    HTMLInputElement* oldCheckedButton = result.first->second;
+    if (oldCheckedButton == inputElement)
+        return;
+
+    result.first->second = inputElement;
+    oldCheckedButton->setChecked(false);
+}
+
 HTMLInputElement* HTMLFormElement::CheckedRadioButtons::checkedButtonForGroup(const AtomicString& name) const
 {
     if (!m_nameToCheckedRadioButtonMap)