From 0e6d5d8188f548cfca55095b799d3f233f52c36f Mon Sep 17 00:00:00 2001 From: Jonas Sicking Date: Mon, 8 Mar 2010 07:45:00 -0800 Subject: [PATCH] Bug 534136 Part 3: Optimize atom-using code for the fact that atoms store 16bit strings. Also take advantage of new nsAtomString API. r=bz --- accessible/src/base/nsAccUtils.cpp | 7 ++--- content/base/public/nsINodeInfo.h | 8 ++--- content/base/src/nsAttrAndChildArray.cpp | 2 +- content/base/src/nsAttrAndChildArray.h | 3 +- content/base/src/nsAttrName.h | 4 +-- content/base/src/nsAttrValue.cpp | 7 +++-- content/base/src/nsDOMAttributeMap.cpp | 3 +- content/base/src/nsGenericElement.cpp | 13 +++----- content/base/src/nsHTMLContentSerializer.cpp | 13 +++----- content/base/src/nsMappedAttributes.cpp | 4 +-- content/base/src/nsMappedAttributes.h | 2 +- content/base/src/nsNodeInfo.cpp | 12 +++---- content/base/src/nsNodeInfo.h | 2 +- content/base/src/nsPlainTextSerializer.cpp | 3 +- content/base/src/nsXHTMLContentSerializer.cpp | 4 +-- content/base/src/nsXMLContentSerializer.cpp | 10 +++--- content/events/src/nsDOMEvent.cpp | 4 +-- content/events/src/nsEventListenerManager.cpp | 4 +-- .../html/content/src/nsGenericHTMLElement.cpp | 6 ++-- .../html/document/src/nsHTMLContentSink.cpp | 10 ++---- content/smil/nsSMILAnimationController.cpp | 5 ++- content/smil/nsSMILCompositor.cpp | 5 ++- content/svg/content/src/nsSVGElement.cpp | 14 +++------ content/svg/content/src/nsSVGLength.cpp | 4 +-- content/xbl/src/nsXBLBinding.cpp | 14 ++++----- content/xbl/src/nsXBLPrototypeHandler.cpp | 12 ++----- content/xslt/src/xpath/txExprLexer.cpp | 10 +++--- content/xslt/src/xpath/txFunctionCall.cpp | 10 +++--- .../src/xpath/txMozillaXPathTreeWalker.cpp | 6 ++-- content/xslt/src/xslt/txUnknownHandler.cpp | 6 ++-- content/xul/content/src/nsXULElement.cpp | 9 ++---- content/xul/document/src/nsXULDocument.cpp | 24 +++----------- .../xul/templates/src/nsXULContentUtils.cpp | 9 ++---- .../src/nsXULTemplateQueryProcessorRDF.cpp | 9 +++--- layout/base/nsCSSFrameConstructor.cpp | 4 +-- layout/inspector/src/inDOMView.cpp | 3 +- layout/style/nsCSSRules.cpp | 5 +-- layout/style/nsCSSStyleRule.cpp | 5 ++- layout/style/nsCSSStyleSheet.cpp | 31 +++++++++---------- layout/xul/base/src/nsSliderFrame.cpp | 5 ++- parser/htmlparser/src/nsParserService.cpp | 5 +-- 41 files changed, 120 insertions(+), 196 deletions(-) diff --git a/accessible/src/base/nsAccUtils.cpp b/accessible/src/base/nsAccUtils.cpp index 3d0394d24247..e3335e7adae4 100644 --- a/accessible/src/base/nsAccUtils.cpp +++ b/accessible/src/base/nsAccUtils.cpp @@ -64,9 +64,7 @@ nsAccUtils::GetAccAttr(nsIPersistentProperties *aAttributes, { aAttrValue.Truncate(); - nsCAutoString attrName; - aAttrName->ToUTF8String(attrName); - aAttributes->GetStringProperty(attrName, aAttrValue); + aAttributes->GetStringProperty(nsAtomCString(aAttrName), aAttrValue); } void @@ -76,8 +74,7 @@ nsAccUtils::SetAccAttr(nsIPersistentProperties *aAttributes, nsAutoString oldValue; nsCAutoString attrName; - aAttrName->ToUTF8String(attrName); - aAttributes->SetStringProperty(attrName, aAttrValue, oldValue); + aAttributes->SetStringProperty(nsAtomCString(aAttrName), aAttrValue, oldValue); } void diff --git a/content/base/public/nsINodeInfo.h b/content/base/public/nsINodeInfo.h index b1e1ac51be87..1983f9aa479e 100644 --- a/content/base/public/nsINodeInfo.h +++ b/content/base/public/nsINodeInfo.h @@ -270,13 +270,13 @@ public: if (!GetPrefixAtom()) return Equals(aNameAtom); - return QualifiedNameEqualsInternal(nsAtomCString(aNameAtom)); + return QualifiedNameEqualsInternal(nsDependentAtomString(aNameAtom)); } - PRBool QualifiedNameEquals(const nsACString& aQualifiedName) const + PRBool QualifiedNameEquals(const nsAString& aQualifiedName) const { if (!GetPrefixAtom()) - return mInner.mName->EqualsUTF8(aQualifiedName); + return mInner.mName->Equals(aQualifiedName); return QualifiedNameEqualsInternal(aQualifiedName); } @@ -291,7 +291,7 @@ public: protected: virtual PRBool - QualifiedNameEqualsInternal(const nsACString& aQualifiedName) const = 0; + QualifiedNameEqualsInternal(const nsAString& aQualifiedName) const = 0; /* * nsNodeInfoInner is used for two things: diff --git a/content/base/src/nsAttrAndChildArray.cpp b/content/base/src/nsAttrAndChildArray.cpp index d019de5042e6..4d1883cab0dc 100644 --- a/content/base/src/nsAttrAndChildArray.cpp +++ b/content/base/src/nsAttrAndChildArray.cpp @@ -513,7 +513,7 @@ nsAttrAndChildArray::GetSafeAttrNameAt(PRUint32 aPos) const } const nsAttrName* -nsAttrAndChildArray::GetExistingAttrNameFromQName(const nsACString& aName) const +nsAttrAndChildArray::GetExistingAttrNameFromQName(const nsAString& aName) const { PRUint32 i, slotCount = AttrSlotCount(); for (i = 0; i < slotCount && mImpl->mBuffer[i * ATTRSIZE]; ++i) { diff --git a/content/base/src/nsAttrAndChildArray.h b/content/base/src/nsAttrAndChildArray.h index 5223d8fac026..cc2cd4d5d168 100644 --- a/content/base/src/nsAttrAndChildArray.h +++ b/content/base/src/nsAttrAndChildArray.h @@ -114,8 +114,7 @@ public: // Returns attribute name at given position or null if aPos is out-of-bounds const nsAttrName* GetSafeAttrNameAt(PRUint32 aPos) const; - // aName is UTF-8 encoded - const nsAttrName* GetExistingAttrNameFromQName(const nsACString& aName) const; + const nsAttrName* GetExistingAttrNameFromQName(const nsAString& aName) const; PRInt32 IndexOfAttr(nsIAtom* aLocalName, PRInt32 aNamespaceID = kNameSpaceID_None) const; nsresult SetAndTakeMappedAttr(nsIAtom* aLocalName, nsAttrValue& aValue, diff --git a/content/base/src/nsAttrName.h b/content/base/src/nsAttrName.h index e906887d08c2..b43d8547a908 100644 --- a/content/base/src/nsAttrName.h +++ b/content/base/src/nsAttrName.h @@ -175,9 +175,9 @@ public: return IsAtom() ? nsnull : NodeInfo()->GetPrefixAtom(); } - PRBool QualifiedNameEquals(const nsACString& aName) const + PRBool QualifiedNameEquals(const nsAString& aName) const { - return IsAtom() ? Atom()->EqualsUTF8(aName) : + return IsAtom() ? Atom()->Equals(aName) : NodeInfo()->QualifiedNameEquals(aName); } diff --git a/content/base/src/nsAttrValue.cpp b/content/base/src/nsAttrValue.cpp index ef298e5e9c98..5ae46b4a50c6 100644 --- a/content/base/src/nsAttrValue.cpp +++ b/content/base/src/nsAttrValue.cpp @@ -716,10 +716,11 @@ nsAttrValue::Equals(const nsAString& aValue, return aValue.IsEmpty(); } case eAtomBase: - // Need a way to just do case-insensitive compares on atoms.. if (aCaseSensitive == eCaseMatters) { - return static_cast(GetPtr())->Equals(aValue);; + return static_cast(GetPtr())->Equals(aValue); } + return nsDependentAtomString(static_cast(GetPtr())). + Equals(aValue, nsCaseInsensitiveStringComparator()); default: break; } @@ -749,7 +750,7 @@ nsAttrValue::Equals(nsIAtom* aValue, nsCaseTreatment aCaseSensitive) const str->StorageSize()/sizeof(PRUnichar) - 1); return aValue->Equals(dep); } - return aValue->EqualsUTF8(EmptyCString()); + return aValue == nsGkAtoms::_empty; } case eAtomBase: { diff --git a/content/base/src/nsDOMAttributeMap.cpp b/content/base/src/nsDOMAttributeMap.cpp index 2df085e5e304..59f3f129616e 100644 --- a/content/base/src/nsDOMAttributeMap.cpp +++ b/content/base/src/nsDOMAttributeMap.cpp @@ -468,7 +468,6 @@ nsDOMAttributeMap::GetNamedItemNSInternal(const nsAString& aNamespaceURI, return NS_OK; } - NS_ConvertUTF16toUTF8 utf8Name(aLocalName); PRInt32 nameSpaceID = kNameSpaceID_None; if (!aNamespaceURI.IsEmpty()) { @@ -487,7 +486,7 @@ nsDOMAttributeMap::GetNamedItemNSInternal(const nsAString& aNamespaceURI, nsIAtom* nameAtom = name->LocalName(); if (nameSpaceID == attrNS && - nameAtom->EqualsUTF8(utf8Name)) { + nameAtom->Equals(aLocalName)) { nsCOMPtr ni; ni = mContent->NodeInfo()->NodeInfoManager()-> GetNodeInfo(nameAtom, name->GetPrefix(), nameSpaceID); diff --git a/content/base/src/nsGenericElement.cpp b/content/base/src/nsGenericElement.cpp index 744db3962776..1e5d7b7ca8b9 100644 --- a/content/base/src/nsGenericElement.cpp +++ b/content/base/src/nsGenericElement.cpp @@ -4265,8 +4265,7 @@ nsGenericElement::AddScriptEventListener(nsIAtom* aEventName, const nsAttrName* nsGenericElement::InternalGetExistingAttrNameFromQName(const nsAString& aStr) const { - return mAttrsAndChildren.GetExistingAttrNameFromQName( - NS_ConvertUTF16toUTF8(aStr)); + return mAttrsAndChildren.GetExistingAttrNameFromQName(aStr); } nsresult @@ -4423,12 +4422,11 @@ nsGenericElement::SetAttrAndNotify(PRInt32 aNamespaceID, nsMutationEvent mutation(PR_TRUE, NS_MUTATION_ATTRMODIFIED); - nsAutoString attrName; - aName->ToString(attrName); nsCOMPtr attrNode; nsAutoString ns; nsContentUtils::NameSpaceManager()->GetNameSpaceURI(aNamespaceID, ns); - GetAttributeNodeNS(ns, attrName, getter_AddRefs(attrNode)); + GetAttributeNodeNS(ns, nsDependentAtomString(aName), + getter_AddRefs(attrNode)); mutation.mRelatedNode = attrNode; mutation.mAttrName = aName; @@ -4626,11 +4624,10 @@ nsGenericElement::UnsetAttr(PRInt32 aNameSpaceID, nsIAtom* aName, // Grab the attr node if needed before we remove it from the attr map nsCOMPtr attrNode; if (hasMutationListeners) { - nsAutoString attrName; - aName->ToString(attrName); nsAutoString ns; nsContentUtils::NameSpaceManager()->GetNameSpaceURI(aNameSpaceID, ns); - GetAttributeNodeNS(ns, attrName, getter_AddRefs(attrNode)); + GetAttributeNodeNS(ns, nsDependentAtomString(aName), + getter_AddRefs(attrNode)); } // Clear binding to nsIDOMNamedNodeMap diff --git a/content/base/src/nsHTMLContentSerializer.cpp b/content/base/src/nsHTMLContentSerializer.cpp index 19d2bbd729b7..317810b089ef 100644 --- a/content/base/src/nsHTMLContentSerializer.cpp +++ b/content/base/src/nsHTMLContentSerializer.cpp @@ -111,7 +111,7 @@ nsHTMLContentSerializer::SerializeHTMLAttributes(nsIContent* aContent, return; nsresult rv; - nsAutoString nameStr, valueStr; + nsAutoString valueStr; NS_NAMED_LITERAL_STRING(_mozStr, "_moz"); for (PRInt32 index = count; index > 0;) { @@ -179,7 +179,7 @@ nsHTMLContentSerializer::SerializeHTMLAttributes(nsIContent* aContent, } } - attrName->ToString(nameStr); + nsDependentAtomString nameStr(attrName); // Expand shorthand attribute. if (IsShorthandAttr(attrName, aTagName) && valueStr.IsEmpty()) { @@ -235,9 +235,7 @@ nsHTMLContentSerializer::AppendElementStart(nsIDOMElement *aElement, AppendToString(kLessThan, aStr); - nsAutoString nameStr; - name->ToString(nameStr); - AppendToString(nameStr.get(), -1, aStr); + AppendToString(nsDependentAtomString(name), aStr); MaybeEnterInPreContent(content); @@ -375,11 +373,8 @@ nsHTMLContentSerializer::AppendElementEnd(nsIDOMElement *aElement, mAddSpace = PR_FALSE; } - nsAutoString nameStr; - name->ToString(nameStr); - AppendToString(kEndTag, aStr); - AppendToString(nameStr.get(), -1, aStr); + AppendToString(nsDependentAtomString(name), aStr); AppendToString(kGreaterThan, aStr); MaybeLeaveFromPreContent(content); diff --git a/content/base/src/nsMappedAttributes.cpp b/content/base/src/nsMappedAttributes.cpp index eb0f7634a780..a58e845cf9bd 100644 --- a/content/base/src/nsMappedAttributes.cpp +++ b/content/base/src/nsMappedAttributes.cpp @@ -244,12 +244,12 @@ nsMappedAttributes::RemoveAttrAt(PRUint32 aPos, nsAttrValue& aValue) } const nsAttrName* -nsMappedAttributes::GetExistingAttrNameFromQName(const nsACString& aName) const +nsMappedAttributes::GetExistingAttrNameFromQName(const nsAString& aName) const { PRUint32 i; for (i = 0; i < mAttrCount; ++i) { if (Attrs()[i].mName.IsAtom()) { - if (Attrs()[i].mName.Atom()->EqualsUTF8(aName)) { + if (Attrs()[i].mName.Atom()->Equals(aName)) { return &Attrs()[i].mName; } } diff --git a/content/base/src/nsMappedAttributes.h b/content/base/src/nsMappedAttributes.h index 5c86e3be38b1..cb196b4efaf4 100644 --- a/content/base/src/nsMappedAttributes.h +++ b/content/base/src/nsMappedAttributes.h @@ -98,7 +98,7 @@ public: // Remove the attr at position aPos. The value of the attr is placed in // aValue; any value that was already in aValue is destroyed. void RemoveAttrAt(PRUint32 aPos, nsAttrValue& aValue); - const nsAttrName* GetExistingAttrNameFromQName(const nsACString& aName) const; + const nsAttrName* GetExistingAttrNameFromQName(const nsAString& aName) const; PRInt32 IndexOfAttr(nsIAtom* aLocalName, PRInt32 aNamespaceID) const; diff --git a/content/base/src/nsNodeInfo.cpp b/content/base/src/nsNodeInfo.cpp index 5488fff01a03..2533a64a4562 100644 --- a/content/base/src/nsNodeInfo.cpp +++ b/content/base/src/nsNodeInfo.cpp @@ -248,16 +248,16 @@ nsNodeInfo::NamespaceEquals(const nsAString& aNamespaceURI) const } PRBool -nsNodeInfo::QualifiedNameEqualsInternal(const nsACString& aQualifiedName) const +nsNodeInfo::QualifiedNameEqualsInternal(const nsAString& aQualifiedName) const { NS_PRECONDITION(mInner.mPrefix, "Must have prefix"); - nsACString::const_iterator start; + nsAString::const_iterator start; aQualifiedName.BeginReading(start); - nsACString::const_iterator colon(start); + nsAString::const_iterator colon(start); - nsAtomCString prefix(mInner.mPrefix); + nsDependentAtomString prefix(mInner.mPrefix); if (prefix.Length() >= aQualifiedName.Length()) { return PR_FALSE; @@ -277,12 +277,12 @@ nsNodeInfo::QualifiedNameEqualsInternal(const nsACString& aQualifiedName) const ++colon; // Skip the ':' - nsACString::const_iterator end; + nsAString::const_iterator end; aQualifiedName.EndReading(end); // Compare the local name to the string between the colon and the // end of aQualifiedName - return mInner.mName->EqualsUTF8(Substring(colon, end)); + return mInner.mName->Equals(Substring(colon, end)); } // static diff --git a/content/base/src/nsNodeInfo.h b/content/base/src/nsNodeInfo.h index cc6d07c87bc6..054584238890 100644 --- a/content/base/src/nsNodeInfo.h +++ b/content/base/src/nsNodeInfo.h @@ -70,7 +70,7 @@ public: PRInt32 aNamespaceID) const; virtual PRBool NamespaceEquals(const nsAString& aNamespaceURI) const; virtual PRBool - QualifiedNameEqualsInternal(const nsACString& aQualifiedName) const; + QualifiedNameEqualsInternal(const nsAString& aQualifiedName) const; // nsNodeInfo // Create objects with Create diff --git a/content/base/src/nsPlainTextSerializer.cpp b/content/base/src/nsPlainTextSerializer.cpp index 4fc29c71ff71..829ee51fe718 100644 --- a/content/base/src/nsPlainTextSerializer.cpp +++ b/content/base/src/nsPlainTextSerializer.cpp @@ -1818,8 +1818,7 @@ nsPlainTextSerializer::GetAttributeValue(const nsIParserNode* aNode, } } else if (aNode) { - nsAutoString name; - aName->ToString(name); + nsDependentAtomString name(aName); PRInt32 count = aNode->GetAttributeCount(); for (PRInt32 i=0;iGetAttr(namespaceID, attrName, valueStr); - attrName->ToString(nameStr); + nsDependentAtomString nameStr(attrName); // XXX Hack to get around the fact that MathML can add // attributes starting with '-', which makes them diff --git a/content/base/src/nsXMLContentSerializer.cpp b/content/base/src/nsXMLContentSerializer.cpp index 0135830fda51..ac681567b2b8 100644 --- a/content/base/src/nsXMLContentSerializer.cpp +++ b/content/base/src/nsXMLContentSerializer.cpp @@ -718,7 +718,7 @@ nsXMLContentSerializer::ScanNamespaceDeclarations(nsIContent* aContent, const nsAString& aTagNamespaceURI) { PRUint32 index, count; - nsAutoString nameStr, prefixStr, uriStr, valueStr; + nsAutoString uriStr, valueStr; count = aContent->GetAttrCount(); @@ -758,8 +758,8 @@ nsXMLContentSerializer::ScanNamespaceDeclarations(nsIContent* aContent, } } else { - attrName->ToString(nameStr); - PushNameSpaceDecl(nameStr, uriStr, aOriginalElement); + PushNameSpaceDecl(nsDependentAtomString(attrName), uriStr, + aOriginalElement); } } } @@ -819,7 +819,7 @@ nsXMLContentSerializer::SerializeAttributes(nsIContent* aContent, PRBool aAddNSAttr) { - nsAutoString nameStr, prefixStr, uriStr, valueStr; + nsAutoString prefixStr, uriStr, valueStr; nsAutoString xmlnsStr; xmlnsStr.AssignLiteral(kXMLNS); PRUint32 index, count; @@ -867,7 +867,7 @@ nsXMLContentSerializer::SerializeAttributes(nsIContent* aContent, } aContent->GetAttr(namespaceID, attrName, valueStr); - attrName->ToString(nameStr); + nsDependentAtomString nameStr(attrName); // XXX Hack to get around the fact that MathML can add // attributes starting with '-', which makes them diff --git a/content/events/src/nsDOMEvent.cpp b/content/events/src/nsDOMEvent.cpp index 82283faa495c..26b927a4607b 100644 --- a/content/events/src/nsDOMEvent.cpp +++ b/content/events/src/nsDOMEvent.cpp @@ -250,9 +250,7 @@ NS_METHOD nsDOMEvent::GetType(nsAString& aType) mCachedType = aType; return NS_OK; } else if (mEvent->message == NS_USER_DEFINED_EVENT && mEvent->userType) { - nsAutoString name; - mEvent->userType->ToString(name); - aType = Substring(name, 2, name.Length() - 2); // Remove "on" + aType = Substring(nsDependentAtomString(mEvent->userType), 2); // Remove "on" mCachedType = aType; return NS_OK; } diff --git a/content/events/src/nsEventListenerManager.cpp b/content/events/src/nsEventListenerManager.cpp index 656683a73a2d..40e45b834931 100644 --- a/content/events/src/nsEventListenerManager.cpp +++ b/content/events/src/nsEventListenerManager.cpp @@ -1484,10 +1484,8 @@ nsEventListenerManager::GetListenerInfo(nsCOMArray* aList) } else if (ls.mEventType == NS_USER_DEFINED_EVENT) { // Handle user defined event types. if (ls.mTypeAtom) { - nsAutoString atomName; - ls.mTypeAtom->ToString(atomName); const nsDependentSubstring& eventType = - Substring(atomName, 2, atomName.Length() - 2); + Substring(nsDependentAtomString(ls.mTypeAtom), 2); nsRefPtr info = new nsEventListenerInfo(eventType, ls.mListener, capturing, allowsUntrusted, systemGroup); diff --git a/content/html/content/src/nsGenericHTMLElement.cpp b/content/html/content/src/nsGenericHTMLElement.cpp index 53f81c45c872..3bd209d7c9fc 100644 --- a/content/html/content/src/nsGenericHTMLElement.cpp +++ b/content/html/content/src/nsGenericHTMLElement.cpp @@ -2999,12 +2999,10 @@ nsGenericHTMLElement::InternalGetExistingAttrNameFromQName(const nsAString& aStr if (IsInHTMLDocument()) { nsAutoString lower; nsContentUtils::ASCIIToLower(aStr, lower); - return mAttrsAndChildren.GetExistingAttrNameFromQName( - NS_ConvertUTF16toUTF8(lower)); + return mAttrsAndChildren.GetExistingAttrNameFromQName(lower); } - return mAttrsAndChildren.GetExistingAttrNameFromQName( - NS_ConvertUTF16toUTF8(aStr)); + return mAttrsAndChildren.GetExistingAttrNameFromQName(aStr); } nsresult diff --git a/content/html/document/src/nsHTMLContentSink.cpp b/content/html/document/src/nsHTMLContentSink.cpp index 40cbf5abc93f..224131b934ad 100644 --- a/content/html/document/src/nsHTMLContentSink.cpp +++ b/content/html/document/src/nsHTMLContentSink.cpp @@ -425,7 +425,6 @@ HTMLContentSink::AddAttributes(const nsIParserNode& aNode, return NS_OK; } - nsCAutoString k; nsHTMLTag nodeType = nsHTMLTag(aNode.GetNodeType()); // The attributes are on the parser node in the order they came in in the @@ -454,15 +453,12 @@ HTMLContentSink::AddAttributes(const nsIParserNode& aNode, step = -1; } + nsAutoString key; for (; i != limit; i += step) { // Get lower-cased key - const nsAString& key = aNode.GetKeyAt(i); - // Copy up-front to avoid shared-buffer overhead (and convert to UTF-8 - // at the same time since that's what the atom table uses). - CopyUTF16toUTF8(key, k); - ToLowerCase(k); + nsContentUtils::ASCIIToLower(aNode.GetKeyAt(i), key); - nsCOMPtr keyAtom = do_GetAtom(k); + nsCOMPtr keyAtom = do_GetAtom(key); if (aCheckIfPresent && aContent->HasAttr(kNameSpaceID_None, keyAtom)) { continue; diff --git a/content/smil/nsSMILAnimationController.cpp b/content/smil/nsSMILAnimationController.cpp index 7c430c712ab3..9fda1a9b34a3 100644 --- a/content/smil/nsSMILAnimationController.cpp +++ b/content/smil/nsSMILAnimationController.cpp @@ -643,9 +643,8 @@ nsSMILAnimationController::GetTargetIdentifierForAnimation( // overlap, 'auto' = 'CSS'. (SMILANIM 3.1) PRBool isCSS; if (attributeType == eSMILTargetAttrType_auto) { - nsAutoString attributeNameStr; - attributeName->ToString(attributeNameStr); - nsCSSProperty prop = nsCSSProps::LookupProperty(attributeNameStr); + nsCSSProperty prop = + nsCSSProps::LookupProperty(nsDependentAtomString(attributeName)); isCSS = nsSMILCSSProperty::IsPropertyAnimatable(prop); } else { isCSS = (attributeType == eSMILTargetAttrType_CSS); diff --git a/content/smil/nsSMILCompositor.cpp b/content/smil/nsSMILCompositor.cpp index 081b75f38bce..d58380574b6e 100644 --- a/content/smil/nsSMILCompositor.cpp +++ b/content/smil/nsSMILCompositor.cpp @@ -149,9 +149,8 @@ nsISMILAttr* nsSMILCompositor::CreateSMILAttr() { if (mKey.mIsCSS) { - nsAutoString name; - mKey.mAttributeName->ToString(name); - nsCSSProperty propId = nsCSSProps::LookupProperty(name); + nsCSSProperty propId = + nsCSSProps::LookupProperty(nsDependentAtomString(mKey.mAttributeName)); if (nsSMILCSSProperty::IsPropertyAnimatable(propId)) { return new nsSMILCSSProperty(propId, mKey.mElement.get()); } diff --git a/content/svg/content/src/nsSVGElement.cpp b/content/svg/content/src/nsSVGElement.cpp index 77804e633448..176d109fb388 100644 --- a/content/svg/content/src/nsSVGElement.cpp +++ b/content/svg/content/src/nsSVGElement.cpp @@ -1087,16 +1087,13 @@ nsSVGElement::UpdateContentStyleRule() } } - nsAutoString name; - attrName->Atom()->ToString(name); - nsAutoString value; mAttrsAndChildren.AttrAt(i)->ToString(value); PRBool changed; - parser.ParseProperty(nsCSSProps::LookupProperty(name), value, - docURI, baseURI, NodePrincipal(), - declaration, &changed); + parser.ParseProperty( + nsCSSProps::LookupProperty(nsAtomString(attrName->Atom())), value, + docURI, baseURI, NodePrincipal(), declaration, &changed); } if (declaration) { @@ -1736,10 +1733,9 @@ nsSVGElement::ReportAttributeParseFailure(nsIDocument* aDocument, nsIAtom* aAttribute, const nsAString& aValue) { - nsAutoString attributeName; - aAttribute->ToString(attributeName); const nsAFlatString& attributeValue = PromiseFlatString(aValue); - const PRUnichar *strings[] = { attributeName.get(), attributeValue.get() }; + const PRUnichar *strings[] = { aAttribute->GetUTF16String(), + attributeValue.get() }; return nsSVGUtils::ReportToConsole(aDocument, "AttributeParseWarning", strings, NS_ARRAY_LENGTH(strings)); diff --git a/content/svg/content/src/nsSVGLength.cpp b/content/svg/content/src/nsSVGLength.cpp index 27eec0a9ab6a..3aa1fbb88476 100644 --- a/content/svg/content/src/nsSVGLength.cpp +++ b/content/svg/content/src/nsSVGLength.cpp @@ -342,9 +342,7 @@ nsSVGLength::GetValueAsString(nsAString & aValueAsString) return NS_ERROR_UNEXPECTED; } - nsAutoString unitString; - UnitAtom->ToString(unitString); - aValueAsString.Append(unitString); + aValueAsString.Append(nsDependentAtomString(UnitAtom)); return NS_OK; } diff --git a/content/xbl/src/nsXBLBinding.cpp b/content/xbl/src/nsXBLBinding.cpp index 0636df255ddb..711ed2271986 100644 --- a/content/xbl/src/nsXBLBinding.cpp +++ b/content/xbl/src/nsXBLBinding.cpp @@ -851,9 +851,6 @@ nsXBLBinding::InstallEventHandlers() eventAtom == nsGkAtoms::keypress) continue; - nsAutoString type; - eventAtom->ToString(type); - // If this is a command, add it in the system event group, otherwise // add it to the standard event group. @@ -879,7 +876,9 @@ nsXBLBinding::InstallEventHandlers() flags |= NS_PRIV_EVENT_UNTRUSTED_PERMITTED; } - manager->AddEventListenerByType(handler, type, flags, eventGroup); + manager->AddEventListenerByType(handler, + nsDependentAtomString(eventAtom), + flags, eventGroup); } } @@ -1015,9 +1014,6 @@ nsXBLBinding::UnhookEventHandlers() eventAtom == nsGkAtoms::keypress) continue; - nsAutoString type; - eventAtom->ToString(type); - // Figure out if we're using capturing or not. PRInt32 flags = (curr->GetPhase() == NS_PHASE_CAPTURING) ? NS_EVENT_FLAG_CAPTURE : NS_EVENT_FLAG_BUBBLE; @@ -1035,7 +1031,9 @@ nsXBLBinding::UnhookEventHandlers() eventGroup = systemEventGroup; } - manager->RemoveEventListenerByType(handler, type, flags, eventGroup); + manager->RemoveEventListenerByType(handler, + nsDependentAtomString(eventAtom), + flags, eventGroup); } const nsCOMArray* keyHandlers = diff --git a/content/xbl/src/nsXBLPrototypeHandler.cpp b/content/xbl/src/nsXBLPrototypeHandler.cpp index 1920000d3975..754e130fa172 100644 --- a/content/xbl/src/nsXBLPrototypeHandler.cpp +++ b/content/xbl/src/nsXBLPrototypeHandler.cpp @@ -260,11 +260,8 @@ nsXBLPrototypeHandler::ExecuteHandler(nsPIDOMEventTarget* aTarget, // Look for a compiled handler on the element. // Should be compiled and bound with "on" in front of the name. - nsAutoString onEvent(NS_LITERAL_STRING("onxbl")); - nsAutoString str; - mEventName->ToString(str); - onEvent += str; - nsCOMPtr onEventAtom = do_GetAtom(onEvent); + nsCOMPtr onEventAtom = do_GetAtom(NS_LITERAL_STRING("onxbl") + + nsDependentAtomString(mEventName)); // Compile the event handler. PRUint32 stID = nsIProgrammingLanguage::JAVASCRIPT; @@ -442,10 +439,7 @@ nsXBLPrototypeHandler::DispatchXBLCommand(nsPIDOMEventTarget* aTarget, nsIDOMEve else controller = GetController(aTarget); // We're attached to the receiver possibly. - nsAutoString type; - mEventName->ToString(type); - - if (type.EqualsLiteral("keypress") && + if (mEventName == nsGkAtoms::keypress && mDetail == nsIDOMKeyEvent::DOM_VK_SPACE && mMisc == 1) { // get the focused element so that we can pageDown only at diff --git a/content/xslt/src/xpath/txExprLexer.cpp b/content/xslt/src/xpath/txExprLexer.cpp index 26df61785753..0d37f53a5404 100644 --- a/content/xslt/src/xpath/txExprLexer.cpp +++ b/content/xslt/src/xpath/txExprLexer.cpp @@ -179,17 +179,17 @@ txExprLexer::parse(const nsASingleFragmentString& aPattern) } } if (nextIsOperatorToken(prevToken)) { - NS_ConvertUTF16toUTF8 opUTF8(Substring(start, mPosition)); - if (txXPathAtoms::_and->EqualsUTF8(opUTF8)) { + nsDependentSubstring op(Substring(start, mPosition)); + if (txXPathAtoms::_and->Equals(op)) { defType = Token::AND_OP; } - else if (txXPathAtoms::_or->EqualsUTF8(opUTF8)) { + else if (txXPathAtoms::_or->Equals(op)) { defType = Token::OR_OP; } - else if (txXPathAtoms::mod->EqualsUTF8(opUTF8)) { + else if (txXPathAtoms::mod->Equals(op)) { defType = Token::MODULUS_OP; } - else if (txXPathAtoms::div->EqualsUTF8(opUTF8)) { + else if (txXPathAtoms::div->Equals(op)) { defType = Token::DIVIDE_OP; } else { diff --git a/content/xslt/src/xpath/txFunctionCall.cpp b/content/xslt/src/xpath/txFunctionCall.cpp index d3d8d0a08aa7..c2b6f6752d89 100644 --- a/content/xslt/src/xpath/txFunctionCall.cpp +++ b/content/xslt/src/xpath/txFunctionCall.cpp @@ -146,15 +146,15 @@ void FunctionCall::toString(nsAString& aDest) { nsCOMPtr functionNameAtom; - nsAutoString functionName; - if (NS_FAILED(getNameAtom(getter_AddRefs(functionNameAtom))) || - NS_FAILED(functionNameAtom->ToString(functionName))) { + if (NS_FAILED(getNameAtom(getter_AddRefs(functionNameAtom)))) { NS_ERROR("Can't get function name."); return; } - aDest.Append(functionName); - aDest.Append(PRUnichar('(')); + + + aDest.Append(nsDependentAtomString(functionNameAtom) + + NS_LITERAL_STRING("(")); for (PRUint32 i = 0; i < mParams.Length(); ++i) { if (i != 0) { aDest.Append(PRUnichar(',')); diff --git a/content/xslt/src/xpath/txMozillaXPathTreeWalker.cpp b/content/xslt/src/xpath/txMozillaXPathTreeWalker.cpp index ad2320abbaa7..49676b290390 100644 --- a/content/xslt/src/xpath/txMozillaXPathTreeWalker.cpp +++ b/content/xslt/src/xpath/txMozillaXPathTreeWalker.cpp @@ -827,13 +827,13 @@ txXPathNativeNode::getNode(const txXPathNode& aNode, nsIDOMNode** aResult) const nsAttrName* name = aNode.Content()->GetAttrNameAt(aNode.mIndex); - nsAutoString namespaceURI, localname; + nsAutoString namespaceURI; nsContentUtils::NameSpaceManager()->GetNameSpaceURI(name->NamespaceID(), namespaceURI); - name->LocalName()->ToString(localname); nsCOMPtr element = do_QueryInterface(aNode.mNode); nsCOMPtr attr; - element->GetAttributeNodeNS(namespaceURI, localname, + element->GetAttributeNodeNS(namespaceURI, + nsDependentAtomString(name->LocalName()), getter_AddRefs(attr)); return CallQueryInterface(attr, aResult); diff --git a/content/xslt/src/xslt/txUnknownHandler.cpp b/content/xslt/src/xslt/txUnknownHandler.cpp index bc43293ea02d..3c889d7d6718 100644 --- a/content/xslt/src/xslt/txUnknownHandler.cpp +++ b/content/xslt/src/xslt/txUnknownHandler.cpp @@ -99,9 +99,9 @@ txUnknownHandler::startElement(nsIAtom* aPrefix, nsIAtom* aLocalName, // Use aLocalName and not aLowercaseLocalName in case the output // handler cares about case. For eHTMLOutput the handler will hardcode // to 'html' anyway. - nsAutoString name; - aLocalName->ToString(name); - nsresult rv = createHandlerAndFlush(htmlRoot, name, aNsID); + nsresult rv = createHandlerAndFlush(htmlRoot, + nsDependentAtomString(aLocalName), + aNsID); NS_ENSURE_SUCCESS(rv, rv); rv = mEs->mResultHandler->startElement(aPrefix, aLocalName, diff --git a/content/xul/content/src/nsXULElement.cpp b/content/xul/content/src/nsXULElement.cpp index f4507e631dec..27403436fc68 100644 --- a/content/xul/content/src/nsXULElement.cpp +++ b/content/xul/content/src/nsXULElement.cpp @@ -1161,9 +1161,8 @@ nsXULElement::ParseAttribute(PRInt32 aNamespaceID, const nsAttrName* nsXULElement::InternalGetExistingAttrNameFromQName(const nsAString& aStr) const { - NS_ConvertUTF16toUTF8 name(aStr); const nsAttrName* attrName = - mAttrsAndChildren.GetExistingAttrNameFromQName(name); + mAttrsAndChildren.GetExistingAttrNameFromQName(aStr); if (attrName) { return attrName; } @@ -1172,7 +1171,7 @@ nsXULElement::InternalGetExistingAttrNameFromQName(const nsAString& aStr) const PRUint32 i; for (i = 0; i < mPrototype->mNumAttributes; ++i) { attrName = &mPrototype->mAttributes[i].mName; - if (attrName->QualifiedNameEquals(name)) { + if (attrName->QualifiedNameEquals(aStr)) { return attrName; } } @@ -1320,11 +1319,9 @@ nsXULElement::UnsetAttr(PRInt32 aNameSpaceID, nsIAtom* aName, PRBool aNotify) nsCOMPtr attrNode; if (hasMutationListeners) { - nsAutoString attrName; - aName->ToString(attrName); nsAutoString ns; nsContentUtils::NameSpaceManager()->GetNameSpaceURI(aNameSpaceID, ns); - GetAttributeNodeNS(ns, attrName, getter_AddRefs(attrNode)); + GetAttributeNodeNS(ns, nsDependentAtomString(aName), getter_AddRefs(attrNode)); } nsDOMSlots *slots = GetExistingDOMSlots(); diff --git a/content/xul/document/src/nsXULDocument.cpp b/content/xul/document/src/nsXULDocument.cpp index 5009e69a37ce..0e020612c942 100644 --- a/content/xul/document/src/nsXULDocument.cpp +++ b/content/xul/document/src/nsXULDocument.cpp @@ -1071,12 +1071,8 @@ nsXULDocument::AttributeChanged(nsIDocument* aDocument, nsAutoString persist; aElement->GetAttr(kNameSpaceID_None, nsGkAtoms::persist, persist); if (!persist.IsEmpty()) { - nsAutoString attr; - rv = aAttribute->ToString(attr); - if (NS_FAILED(rv)) return; - // XXXldb This should check that it's a token, not just a substring. - if (persist.Find(attr) >= 0) { + if (persist.Find(nsDependentAtomString(aAttribute)) >= 0) { rv = Persist(aElement, kNameSpaceID_None, aAttribute); if (NS_FAILED(rv)) return; } @@ -4186,17 +4182,12 @@ nsXULDocument::BroadcasterHookup::~BroadcasterHookup() attribute.AssignLiteral("*"); } - nsAutoString tagStr; - rv = tag->ToString(tagStr); - if (NS_FAILED(rv)) return; - - nsCAutoString tagstrC, attributeC,broadcasteridC; - tagstrC.AssignWithConversion(tagStr); + nsCAutoString attributeC,broadcasteridC; attributeC.AssignWithConversion(attribute); broadcasteridC.AssignWithConversion(broadcasterID); PR_LOG(gXULLog, PR_LOG_WARNING, ("xul: broadcaster hookup failed <%s attribute='%s'> to %s", - tagstrC.get(), + nsAtomCString(tag).get(), attributeC.get(), broadcasteridC.get())); } @@ -4366,17 +4357,12 @@ nsXULDocument::CheckBroadcasterHookup(nsIContent* aElement, if (! content) return rv; - nsAutoString tagStr; - rv = content->Tag()->ToString(tagStr); - if (NS_FAILED(rv)) return rv; - - nsCAutoString tagstrC, attributeC,broadcasteridC; - tagstrC.AssignWithConversion(tagStr); + nsCAutoString attributeC,broadcasteridC; attributeC.AssignWithConversion(attribute); broadcasteridC.AssignWithConversion(broadcasterID); PR_LOG(gXULLog, PR_LOG_NOTICE, ("xul: broadcaster hookup <%s attribute='%s'> to %s", - tagstrC.get(), + nsAtomCString(content->Tag()).get(), attributeC.get(), broadcasteridC.get())); } diff --git a/content/xul/templates/src/nsXULContentUtils.cpp b/content/xul/templates/src/nsXULContentUtils.cpp index 1fd39df37de1..5123fa81779e 100644 --- a/content/xul/templates/src/nsXULContentUtils.cpp +++ b/content/xul/templates/src/nsXULContentUtils.cpp @@ -395,13 +395,8 @@ nsXULContentUtils::GetResource(PRInt32 aNameSpaceID, nsIAtom* aAttribute, nsIRDF if (! aAttribute) return NS_ERROR_NULL_POINTER; - nsresult rv; - - nsAutoString attr; - rv = aAttribute->ToString(attr); - if (NS_FAILED(rv)) return rv; - - return GetResource(aNameSpaceID, attr, aResult); + return GetResource(aNameSpaceID, nsDependentAtomString(aAttribute), + aResult); } diff --git a/content/xul/templates/src/nsXULTemplateQueryProcessorRDF.cpp b/content/xul/templates/src/nsXULTemplateQueryProcessorRDF.cpp index 3c86c16e66d1..90170ca895ca 100644 --- a/content/xul/templates/src/nsXULTemplateQueryProcessorRDF.cpp +++ b/content/xul/templates/src/nsXULTemplateQueryProcessorRDF.cpp @@ -652,9 +652,9 @@ nsXULTemplateQueryProcessorRDF::TranslateRef(nsISupports* aDatasource, NS_IMETHODIMP nsXULTemplateQueryProcessorRDF::CompareResults(nsIXULTemplateResult* aLeft, - nsIXULTemplateResult* aRight, - nsIAtom* aVar, - PRInt32* aResult) + nsIXULTemplateResult* aRight, + nsIAtom* aVar, + PRInt32* aResult) { NS_ENSURE_ARG_POINTER(aLeft); NS_ENSURE_ARG_POINTER(aRight); @@ -673,8 +673,7 @@ nsXULTemplateQueryProcessorRDF::CompareResults(nsIXULTemplateResult* aLeft, return NS_OK; } - nsAutoString sortkey; - aVar->ToString(sortkey); + nsDependentAtomString sortkey(aVar); nsCOMPtr leftNode, rightNode; diff --git a/layout/base/nsCSSFrameConstructor.cpp b/layout/base/nsCSSFrameConstructor.cpp index 0f3c98fd3541..7d94b26dfc3d 100644 --- a/layout/base/nsCSSFrameConstructor.cpp +++ b/layout/base/nsCSSFrameConstructor.cpp @@ -9113,9 +9113,7 @@ nsCSSFrameConstructor::ProcessChildren(nsFrameConstructorState& aState, // no? And if we cared we could look through the item list // instead of groveling through the framelist here.. nsIContent *badKid = AnyKidsNeedBlockParent(aFrameItems.FirstChild()); - nsAutoString parentTag, kidTag; - aContent->Tag()->ToString(parentTag); - badKid->Tag()->ToString(kidTag); + nsDependentAtomString parentTag(aContent->Tag()), kidTag(badKid->Tag()); const PRUnichar* params[] = { parentTag.get(), kidTag.get() }; nsStyleContext *frameStyleContext = aFrame->GetStyleContext(); const nsStyleDisplay *display = frameStyleContext->GetStyleDisplay(); diff --git a/layout/inspector/src/inDOMView.cpp b/layout/inspector/src/inDOMView.cpp index f6bf9e4aeb23..43f47aa83dfa 100644 --- a/layout/inspector/src/inDOMView.cpp +++ b/layout/inspector/src/inDOMView.cpp @@ -699,8 +699,7 @@ inDOMView::AttributeChanged(nsIDocument *aDocument, nsIContent* aContent, nsCOMPtr content(do_QueryInterface(aContent)); nsCOMPtr el(do_QueryInterface(aContent)); nsCOMPtr domAttr; - nsAutoString attrStr; - aAttribute->ToString(attrStr); + nsDependentAtomString attrStr(aAttribute); if (aNameSpaceID) { nsCOMPtr nsm = do_GetService(NS_NAMESPACEMANAGER_CONTRACTID); diff --git a/layout/style/nsCSSRules.cpp b/layout/style/nsCSSRules.cpp index 7ed8b4676673..10c498d04c01 100644 --- a/layout/style/nsCSSRules.cpp +++ b/layout/style/nsCSSRules.cpp @@ -1441,10 +1441,7 @@ CSSNameSpaceRuleImpl::GetCssText(nsAString& aCssText) { aCssText.AssignLiteral("@namespace "); if (mPrefix) { - nsString atomStr; - mPrefix->ToString(atomStr); - aCssText.Append(atomStr); - aCssText.AppendLiteral(" "); + aCssText.Append(nsDependentAtomString(mPrefix) + NS_LITERAL_STRING(" ")); } aCssText.AppendLiteral("url("); nsStyleUtil::AppendEscapedCSSString(mURLSpec, aCssText); diff --git a/layout/style/nsCSSStyleRule.cpp b/layout/style/nsCSSStyleRule.cpp index 9c5a49e2953e..a160ae73347a 100644 --- a/layout/style/nsCSSStyleRule.cpp +++ b/layout/style/nsCSSStyleRule.cpp @@ -595,9 +595,8 @@ nsCSSSelector::AppendToStringWithoutCombinatorsOrNegations nsIAtom *prefixAtom = sheetNS->FindPrefix(mNameSpace); NS_ASSERTION(prefixAtom, "how'd we get a non-default namespace " "without a prefix?"); - nsAutoString prefix; - prefixAtom->ToString(prefix); - nsStyleUtil::AppendEscapedCSSIdent(prefix, aString); + nsStyleUtil::AppendEscapedCSSIdent(nsDependentAtomString(prefixAtom), + aString); aString.Append(PRUnichar('|')); wroteNamespace = PR_TRUE; } else { diff --git a/layout/style/nsCSSStyleSheet.cpp b/layout/style/nsCSSStyleSheet.cpp index e19d254a075f..4bd978732492 100644 --- a/layout/style/nsCSSStyleSheet.cpp +++ b/layout/style/nsCSSStyleSheet.cpp @@ -375,8 +375,6 @@ nsMediaQueryResultCacheKey::Matches(nsPresContext* aPresContext) const void nsMediaQuery::AppendToString(nsAString& aString) const { - nsAutoString buffer; - if (mHadUnknownExpression) { aString.AppendLiteral("not all"); return; @@ -391,9 +389,7 @@ nsMediaQuery::AppendToString(nsAString& aString) const } else if (mHasOnly) { aString.AppendLiteral("only "); } - mMediaType->ToString(buffer); - aString.Append(buffer); - buffer.Truncate(); + aString.Append(nsDependentAtomString(mMediaType)); } for (PRUint32 i = 0, i_end = mExpressions.Length(); i < i_end; ++i) { @@ -409,9 +405,7 @@ nsMediaQuery::AppendToString(nsAString& aString) const } const nsMediaFeature *feature = expr.mFeature; - (*feature->mName)->ToString(buffer); - aString.Append(buffer); - buffer.Truncate(); + aString.Append(nsDependentAtomString(*feature->mName)); if (expr.mValue.GetUnit() != eCSSUnit_Null) { aString.AppendLiteral(": "); @@ -450,15 +444,18 @@ nsMediaQuery::AppendToString(nsAString& aString) const } break; case nsMediaFeature::eResolution: - buffer.AppendFloat(expr.mValue.GetFloatValue()); - aString.Append(buffer); - buffer.Truncate(); - if (expr.mValue.GetUnit() == eCSSUnit_Inch) { - aString.AppendLiteral("dpi"); - } else { - NS_ASSERTION(expr.mValue.GetUnit() == eCSSUnit_Centimeter, - "bad unit"); - aString.AppendLiteral("dpcm"); + { + nsAutoString buffer; + buffer.AppendFloat(expr.mValue.GetFloatValue()); + aString.Append(buffer); + buffer.Truncate(); + if (expr.mValue.GetUnit() == eCSSUnit_Inch) { + aString.AppendLiteral("dpi"); + } else { + NS_ASSERTION(expr.mValue.GetUnit() == eCSSUnit_Centimeter, + "bad unit"); + aString.AppendLiteral("dpcm"); + } } break; case nsMediaFeature::eEnumerated: diff --git a/layout/xul/base/src/nsSliderFrame.cpp b/layout/xul/base/src/nsSliderFrame.cpp index 082e3b13d58c..10b6d0a8e2cc 100644 --- a/layout/xul/base/src/nsSliderFrame.cpp +++ b/layout/xul/base/src/nsSliderFrame.cpp @@ -223,9 +223,8 @@ public: NS_IMETHODIMP Run() { - nsAutoString which; - mWhich->ToString(which); - return mListener->ValueChanged(which, mValue, mUserChanged); + return mListener->ValueChanged(nsDependentAtomString(mWhich), + mValue, mUserChanged); } nsCOMPtr mListener; diff --git a/parser/htmlparser/src/nsParserService.cpp b/parser/htmlparser/src/nsParserService.cpp index 7165704dfd28..cd78acec668e 100644 --- a/parser/htmlparser/src/nsParserService.cpp +++ b/parser/htmlparser/src/nsParserService.cpp @@ -65,10 +65,7 @@ NS_IMPL_ISUPPORTS1(nsParserService, nsIParserService) PRInt32 nsParserService::HTMLAtomTagToId(nsIAtom* aAtom) const { - nsAutoString tagName; - aAtom->ToString(tagName); - - return nsHTMLTags::LookupTag(tagName); + return nsHTMLTags::LookupTag(nsDependentAtomString(aAtom)); } PRInt32