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
authorJonas Sicking <jonas@sicking.cc>
Mon, 08 Mar 2010 07:45:00 -0800
changeset 39101 1995edaefd3f79ca174f28635cbdce3d6db0bbe8
parent 39100 cb17f4d9294251cebc73861239603fc87c4c45fd
child 39102 5901c6b98f836784818fc0495a1775f02726ee5c
push id12012
push usersicking@mozilla.com
push dateMon, 08 Mar 2010 15:47:04 +0000
treeherdermozilla-central@f8dd7b5b02ef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs534136
milestone1.9.3a3pre
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
content/base/public/nsINodeInfo.h
content/base/src/nsAttrAndChildArray.cpp
content/base/src/nsAttrAndChildArray.h
content/base/src/nsAttrName.h
content/base/src/nsAttrValue.cpp
content/base/src/nsDOMAttributeMap.cpp
content/base/src/nsGenericElement.cpp
content/base/src/nsHTMLContentSerializer.cpp
content/base/src/nsMappedAttributes.cpp
content/base/src/nsMappedAttributes.h
content/base/src/nsNodeInfo.cpp
content/base/src/nsNodeInfo.h
content/base/src/nsPlainTextSerializer.cpp
content/base/src/nsXHTMLContentSerializer.cpp
content/base/src/nsXMLContentSerializer.cpp
content/events/src/nsDOMEvent.cpp
content/events/src/nsEventListenerManager.cpp
content/html/content/src/nsGenericHTMLElement.cpp
content/html/document/src/nsHTMLContentSink.cpp
content/smil/nsSMILAnimationController.cpp
content/smil/nsSMILCompositor.cpp
content/svg/content/src/nsSVGElement.cpp
content/svg/content/src/nsSVGLength.cpp
content/xbl/src/nsXBLBinding.cpp
content/xbl/src/nsXBLPrototypeHandler.cpp
content/xslt/src/xpath/txExprLexer.cpp
content/xslt/src/xpath/txFunctionCall.cpp
content/xslt/src/xpath/txMozillaXPathTreeWalker.cpp
content/xslt/src/xslt/txUnknownHandler.cpp
content/xul/content/src/nsXULElement.cpp
content/xul/document/src/nsXULDocument.cpp
content/xul/templates/src/nsXULContentUtils.cpp
content/xul/templates/src/nsXULTemplateQueryProcessorRDF.cpp
layout/base/nsCSSFrameConstructor.cpp
layout/inspector/src/inDOMView.cpp
layout/style/nsCSSRules.cpp
layout/style/nsCSSStyleRule.cpp
layout/style/nsCSSStyleSheet.cpp
layout/xul/base/src/nsSliderFrame.cpp
parser/htmlparser/src/nsParserService.cpp
--- a/accessible/src/base/nsAccUtils.cpp
+++ b/accessible/src/base/nsAccUtils.cpp
@@ -59,30 +59,27 @@
 #include "nsComponentManagerUtils.h"
 
 void
 nsAccUtils::GetAccAttr(nsIPersistentProperties *aAttributes,
                        nsIAtom *aAttrName, nsAString& aAttrValue)
 {
   aAttrValue.Truncate();
 
-  nsCAutoString attrName;
-  aAttrName->ToUTF8String(attrName);
-  aAttributes->GetStringProperty(attrName, aAttrValue);
+  aAttributes->GetStringProperty(nsAtomCString(aAttrName), aAttrValue);
 }
 
 void
 nsAccUtils::SetAccAttr(nsIPersistentProperties *aAttributes,
                        nsIAtom *aAttrName, const nsAString& aAttrValue)
 {
   nsAutoString oldValue;
   nsCAutoString attrName;
 
-  aAttrName->ToUTF8String(attrName);
-  aAttributes->SetStringProperty(attrName, aAttrValue, oldValue);
+  aAttributes->SetStringProperty(nsAtomCString(aAttrName), aAttrValue, oldValue);
 }
 
 void
 nsAccUtils::SetAccGroupAttrs(nsIPersistentProperties *aAttributes,
                              PRInt32 aLevel, PRInt32 aSetSize,
                              PRInt32 aPosInSet)
 {
   nsAutoString value;
--- a/content/base/public/nsINodeInfo.h
+++ b/content/base/public/nsINodeInfo.h
@@ -265,38 +265,38 @@ public:
   virtual PRBool NamespaceEquals(const nsAString& aNamespaceURI) const = 0;
 
   PRBool QualifiedNameEquals(nsIAtom* aNameAtom) const
   {
     NS_PRECONDITION(aNameAtom, "Must have name atom");
     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);    
   }
 
   /*
    * Retrieve a pointer to the document that owns this node info.
    */
   nsIDocument* GetDocument() const
   {
     return mOwnerManager->GetDocument();
   }
 
 protected:
   virtual PRBool
-    QualifiedNameEqualsInternal(const nsACString& aQualifiedName) const = 0;
+    QualifiedNameEqualsInternal(const nsAString& aQualifiedName) const = 0;
 
   /*
    * nsNodeInfoInner is used for two things:
    *
    *   1. as a member in nsNodeInfo for holding the name, prefix and
    *      namespace ID
    *   2. as the hash key in the hash table in nsNodeInfoManager
    *
--- a/content/base/src/nsAttrAndChildArray.cpp
+++ b/content/base/src/nsAttrAndChildArray.cpp
@@ -508,17 +508,17 @@ nsAttrAndChildArray::GetSafeAttrNameAt(P
   if (!*pos) {
     return nsnull;
   }
 
   return &reinterpret_cast<InternalAttr*>(pos)->mName;
 }
 
 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) {
     if (ATTRS(mImpl)[i].mName.QualifiedNameEquals(aName)) {
       return &ATTRS(mImpl)[i].mName;
     }
   }
 
--- a/content/base/src/nsAttrAndChildArray.h
+++ b/content/base/src/nsAttrAndChildArray.h
@@ -109,18 +109,17 @@ public:
   nsresult RemoveAttrAt(PRUint32 aPos, nsAttrValue& aValue);
 
   // Returns attribute name at given position, *not* out-of-bounds safe
   const nsAttrName* AttrNameAt(PRUint32 aPos) const;
 
   // 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,
                                 nsMappedAttributeElement* aContent,
                                 nsHTMLStyleSheet* aSheet);
   nsresult SetMappedAttrStyleSheet(nsHTMLStyleSheet* aSheet);
   void WalkMappedAttributeStyleRules(nsRuleWalker* aRuleWalker);
 
--- a/content/base/src/nsAttrName.h
+++ b/content/base/src/nsAttrName.h
@@ -170,19 +170,19 @@ public:
     return IsAtom() ? Atom() : NodeInfo()->NameAtom();
   }
 
   nsIAtom* GetPrefix() const
   {
     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);
   }
 
   void GetQualifiedName(nsAString& aStr) const
   {
     if (IsAtom()) {
       Atom()->ToString(aStr);
     }
--- a/content/base/src/nsAttrValue.cpp
+++ b/content/base/src/nsAttrValue.cpp
@@ -711,20 +711,21 @@ nsAttrValue::Equals(const nsAString& aVa
         nsDependentString dep(static_cast<PRUnichar*>(str->Data()),
                               str->StorageSize()/sizeof(PRUnichar) - 1);
         return aCaseSensitive == eCaseMatters ? aValue.Equals(dep) :
           aValue.Equals(dep, nsCaseInsensitiveStringComparator());
       }
       return aValue.IsEmpty();
     }
     case eAtomBase:
-      // Need a way to just do case-insensitive compares on atoms..
       if (aCaseSensitive == eCaseMatters) {
-        return static_cast<nsIAtom*>(GetPtr())->Equals(aValue);;
+        return static_cast<nsIAtom*>(GetPtr())->Equals(aValue);
       }
+      return nsDependentAtomString(static_cast<nsIAtom*>(GetPtr())).
+        Equals(aValue, nsCaseInsensitiveStringComparator());
     default:
       break;
   }
 
   nsAutoString val;
   ToString(val);
   return aCaseSensitive == eCaseMatters ? val.Equals(aValue) :
     val.Equals(aValue, nsCaseInsensitiveStringComparator());
@@ -744,17 +745,17 @@ nsAttrValue::Equals(nsIAtom* aValue, nsC
     case eStringBase:
     {
       nsStringBuffer* str = static_cast<nsStringBuffer*>(GetPtr());
       if (str) {
         nsDependentString dep(static_cast<PRUnichar*>(str->Data()),
                               str->StorageSize()/sizeof(PRUnichar) - 1);
         return aValue->Equals(dep);
       }
-      return aValue->EqualsUTF8(EmptyCString());
+      return aValue == nsGkAtoms::_empty;
     }
     case eAtomBase:
     {
       return static_cast<nsIAtom*>(GetPtr()) == aValue;
     }
     default:
       break;
   }
--- a/content/base/src/nsDOMAttributeMap.cpp
+++ b/content/base/src/nsDOMAttributeMap.cpp
@@ -463,17 +463,16 @@ nsDOMAttributeMap::GetNamedItemNSInterna
 {
   NS_ENSURE_ARG_POINTER(aReturn);
   *aReturn = nsnull;
 
   if (!mContent) {
     return NS_OK;
   }
 
-  NS_ConvertUTF16toUTF8 utf8Name(aLocalName);
   PRInt32 nameSpaceID = kNameSpaceID_None;
 
   if (!aNamespaceURI.IsEmpty()) {
     nameSpaceID =
       nsContentUtils::NameSpaceManager()->GetNameSpaceID(aNamespaceURI);
 
     if (nameSpaceID == kNameSpaceID_Unknown) {
       return NS_OK;
@@ -482,17 +481,17 @@ nsDOMAttributeMap::GetNamedItemNSInterna
 
   PRUint32 i, count = mContent->GetAttrCount();
   for (i = 0; i < count; ++i) {
     const nsAttrName* name = mContent->GetAttrNameAt(i);
     PRInt32 attrNS = name->NamespaceID();
     nsIAtom* nameAtom = name->LocalName();
 
     if (nameSpaceID == attrNS &&
-        nameAtom->EqualsUTF8(utf8Name)) {
+        nameAtom->Equals(aLocalName)) {
       nsCOMPtr<nsINodeInfo> ni;
       ni = mContent->NodeInfo()->NodeInfoManager()->
         GetNodeInfo(nameAtom, name->GetPrefix(), nameSpaceID);
       NS_ENSURE_TRUE(ni, NS_ERROR_OUT_OF_MEMORY);
 
       return aRemove ? RemoveAttribute(ni, aReturn) : GetAttribute(ni, aReturn);
     }
   }
--- a/content/base/src/nsGenericElement.cpp
+++ b/content/base/src/nsGenericElement.cpp
@@ -4260,18 +4260,17 @@ nsGenericElement::AddScriptEventListener
 }
 
 
 //----------------------------------------------------------------------
 
 const nsAttrName*
 nsGenericElement::InternalGetExistingAttrNameFromQName(const nsAString& aStr) const
 {
-  return mAttrsAndChildren.GetExistingAttrNameFromQName(
-    NS_ConvertUTF16toUTF8(aStr));
+  return mAttrsAndChildren.GetExistingAttrNameFromQName(aStr);
 }
 
 nsresult
 nsGenericElement::CopyInnerTo(nsGenericElement* aDst) const
 {
   PRUint32 i, count = mAttrsAndChildren.AttrCount();
   for (i = 0; i < count; ++i) {
     const nsAttrName* name = mAttrsAndChildren.AttrNameAt(i);
@@ -4418,22 +4417,21 @@ nsGenericElement::SetAttrAndNotify(PRInt
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   if (aFireMutation) {
     mozAutoRemovableBlockerRemover blockerRemover(GetOwnerDoc());
     
     nsMutationEvent mutation(PR_TRUE, NS_MUTATION_ATTRMODIFIED);
 
-    nsAutoString attrName;
-    aName->ToString(attrName);
     nsCOMPtr<nsIDOMAttr> 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;
     nsAutoString newValue;
     GetAttr(aNamespaceID, aName, newValue);
     if (!newValue.IsEmpty()) {
       mutation.mNewAttrValue = do_GetAtom(newValue);
     }
@@ -4621,21 +4619,20 @@ nsGenericElement::UnsetAttr(PRInt32 aNam
   PRBool hasMutationListeners = aNotify &&
     nsContentUtils::HasMutationListeners(this,
                                          NS_EVENT_BITS_MUTATION_ATTRMODIFIED,
                                          this);
 
   // Grab the attr node if needed before we remove it from the attr map
   nsCOMPtr<nsIDOMAttr> 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
   nsDOMSlots *slots = GetExistingDOMSlots();
   if (slots && slots->mAttributeMap) {
     slots->mAttributeMap->DropAttribute(aNameSpaceID, aName);
   }
 
--- a/content/base/src/nsHTMLContentSerializer.cpp
+++ b/content/base/src/nsHTMLContentSerializer.cpp
@@ -106,17 +106,17 @@ nsHTMLContentSerializer::SerializeHTMLAt
                                                  nsIAtom* aTagName,
                                                  nsAString& aStr)
 {
   PRInt32 count = aContent->GetAttrCount();
   if (!count)
     return;
 
   nsresult rv;
-  nsAutoString nameStr, valueStr;
+  nsAutoString valueStr;
   NS_NAMED_LITERAL_STRING(_mozStr, "_moz");
 
   for (PRInt32 index = count; index > 0;) {
     --index;
     const nsAttrName* name = aContent->GetAttrNameAt(index);
     PRInt32 namespaceID = name->NamespaceID();
     nsIAtom* attrName = name->LocalName();
 
@@ -174,17 +174,17 @@ nsHTMLContentSerializer::SerializeHTMLAt
       nsAutoString header;
       aContent->GetAttr(kNameSpaceID_None, nsGkAtoms::httpEquiv, header);
       if (header.LowerCaseEqualsLiteral("content-type")) {
         valueStr = NS_LITERAL_STRING("text/html; charset=") +
           NS_ConvertASCIItoUTF16(mCharset);
       }
     }
 
-    attrName->ToString(nameStr);
+    nsDependentAtomString nameStr(attrName);
 
     // Expand shorthand attribute.
     if (IsShorthandAttr(attrName, aTagName) && valueStr.IsEmpty()) {
       valueStr = nameStr;
     }
     SerializeAttr(EmptyString(), nameStr, valueStr, aStr, !isJS);
   }
 }
@@ -230,19 +230,17 @@ nsHTMLContentSerializer::AppendElementSt
     MaybeAddNewlineForRootNode(aStr);
   }
   // Always reset to avoid false newlines in case MaybeAddNewlineForRootNode wasn't
   // called
   mAddNewlineForRootNode = PR_FALSE;
   
   AppendToString(kLessThan, aStr);
 
-  nsAutoString nameStr;
-  name->ToString(nameStr);
-  AppendToString(nameStr.get(), -1, aStr);
+  AppendToString(nsDependentAtomString(name), aStr);
 
   MaybeEnterInPreContent(content);
 
   // for block elements, we increase the indentation
   if ((mDoFormat || forceFormat) && !mPreLevel && !mDoRaw)
     IncrIndentation(name);
 
   // Need to keep track of OL and LI elements in order to get ordinal number 
@@ -370,21 +368,18 @@ nsHTMLContentSerializer::AppendElementEn
       mAddSpace = PR_FALSE;
     }
   }
   else if (mAddSpace) {
     AppendToString(PRUnichar(' '), aStr);
     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);
 
   if ((mDoFormat || forceFormat) && !mPreLevel
       && !mDoRaw && LineBreakAfterClose(content->GetNameSpaceID(), name)) {
     AppendNewLineToString(aStr);
   }
--- a/content/base/src/nsMappedAttributes.cpp
+++ b/content/base/src/nsMappedAttributes.cpp
@@ -239,22 +239,22 @@ nsMappedAttributes::RemoveAttrAt(PRUint3
   Attrs()[aPos].mValue.SwapValueWith(aValue);
   Attrs()[aPos].~InternalAttr();
   memmove(&Attrs()[aPos], &Attrs()[aPos + 1],
           (mAttrCount - aPos - 1) * sizeof(InternalAttr));
   mAttrCount--;
 }
 
 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;
       }
     }
     else {
       if (Attrs()[i].mName.NodeInfo()->QualifiedNameEquals(aName)) {
         return &Attrs()[i].mName;
       }
     }
--- a/content/base/src/nsMappedAttributes.h
+++ b/content/base/src/nsMappedAttributes.h
@@ -93,17 +93,17 @@ public:
   const nsAttrValue* AttrAt(PRUint32 aPos) const
   {
     NS_ASSERTION(aPos < mAttrCount, "out-of-bounds");
     return &Attrs()[aPos].mValue;
   }
   // 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;
   
 
   // nsIStyleRule 
   NS_IMETHOD MapRuleInfoInto(nsRuleData* aRuleData);
 #ifdef DEBUG
   NS_METHOD List(FILE* out = stdout, PRInt32 aIndent = 0) const;
 #endif
--- a/content/base/src/nsNodeInfo.cpp
+++ b/content/base/src/nsNodeInfo.cpp
@@ -243,26 +243,26 @@ nsNodeInfo::NamespaceEquals(const nsAStr
 {
   PRInt32 nsid =
     nsContentUtils::NameSpaceManager()->GetNameSpaceID(aNamespaceURI);
 
   return nsINodeInfo::NamespaceEquals(nsid);
 }
 
 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;
   }
 
   colon.advance(prefix.Length());
 
   // If the character at the prefix length index is not a colon,
@@ -272,22 +272,22 @@ nsNodeInfo::QualifiedNameEqualsInternal(
   }
 
   // Compare the prefix to the string from the start to the colon
   if (!prefix.Equals(Substring(start, colon)))
     return PR_FALSE;
 
   ++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
 void
 nsNodeInfo::ClearCache()
 {
   // Clear our cache.
   delete sNodeInfoPool;
--- a/content/base/src/nsNodeInfo.h
+++ b/content/base/src/nsNodeInfo.h
@@ -65,17 +65,17 @@ public:
   virtual PRBool Equals(const nsAString& aName) const;
   virtual PRBool Equals(const nsAString& aName,
                         const nsAString& aPrefix) const;
   virtual PRBool Equals(const nsAString& aName, PRInt32 aNamespaceID) const;
   virtual PRBool Equals(const nsAString& aName, const nsAString& aPrefix,
                         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
 public:
   static nsNodeInfo *Create();
 private:
   nsNodeInfo();
 protected:
--- a/content/base/src/nsPlainTextSerializer.cpp
+++ b/content/base/src/nsPlainTextSerializer.cpp
@@ -1813,18 +1813,17 @@ nsPlainTextSerializer::GetAttributeValue
                                          nsString& aValueRet)
 {
   if (mContent) {
     if (mContent->GetAttr(kNameSpaceID_None, aName, aValueRet)) {
       return NS_OK;
     }
   }
   else if (aNode) {
-    nsAutoString name; 
-    aName->ToString(name);
+    nsDependentAtomString name(aName); 
 
     PRInt32 count = aNode->GetAttributeCount();
     for (PRInt32 i=0;i<count;i++) {
       const nsAString& key = aNode->GetKeyAt(i);
       if (key.Equals(name, nsCaseInsensitiveStringComparator())) {
         aValueRet = aNode->GetValueAt(i);
         return NS_OK;
       }
--- a/content/base/src/nsXHTMLContentSerializer.cpp
+++ b/content/base/src/nsXHTMLContentSerializer.cpp
@@ -266,17 +266,17 @@ nsXHTMLContentSerializer::SerializeAttri
                                               const nsAString& aTagNamespaceURI,
                                               nsIAtom* aTagName,
                                               nsAString& aStr,
                                               PRUint32 aSkipAttr,
                                               PRBool aAddNSAttr)
 {
   nsresult rv;
   PRUint32 index, count;
-  nsAutoString nameStr, prefixStr, uriStr, valueStr;
+  nsAutoString prefixStr, uriStr, valueStr;
   nsAutoString xmlnsStr;
   xmlnsStr.AssignLiteral(kXMLNS);
 
   PRInt32 contentNamespaceID = aContent->GetNameSpaceID();
 
   // this method is not called by nsHTMLContentSerializer
   // so we don't have to check HTML element, just XHTML
 
@@ -362,17 +362,17 @@ nsXHTMLContentSerializer::SerializeAttri
     PRBool addNSAttr = PR_FALSE;
     if (kNameSpaceID_XMLNS != namespaceID) {
       nsContentUtils::NameSpaceManager()->GetNameSpaceURI(namespaceID, uriStr);
       addNSAttr = ConfirmPrefix(prefixStr, uriStr, aOriginalElement, PR_TRUE);
     }
 
     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
     //     invalid XML. see Bug 475518
     if (!nameStr.IsEmpty() && nameStr.First() == '-')
       continue;
 
     PRBool isJS = PR_FALSE;
--- a/content/base/src/nsXMLContentSerializer.cpp
+++ b/content/base/src/nsXMLContentSerializer.cpp
@@ -713,17 +713,17 @@ nsXMLContentSerializer::SerializeAttr(co
 }
 
 PRUint32 
 nsXMLContentSerializer::ScanNamespaceDeclarations(nsIContent* aContent,
                                                   nsIDOMElement *aOriginalElement,
                                                   const nsAString& aTagNamespaceURI)
 {
   PRUint32 index, count;
-  nsAutoString nameStr, prefixStr, uriStr, valueStr;
+  nsAutoString uriStr, valueStr;
 
   count = aContent->GetAttrCount();
 
   // First scan for namespace declarations, pushing each on the stack
   PRUint32 skipAttr = count;
   for (index = 0; index < count; index++) {
     
     const nsAttrName* name = aContent->GetAttrNameAt(index);
@@ -753,18 +753,18 @@ nsXMLContentSerializer::ScanNamespaceDec
           skipAttr = index;
         }
         else {
           // Default NS attribute does not have prefix (and the name is "xmlns")
           PushNameSpaceDecl(EmptyString(), uriStr, aOriginalElement);
         }
       }
       else {
-        attrName->ToString(nameStr);
-        PushNameSpaceDecl(nameStr, uriStr, aOriginalElement);
+        PushNameSpaceDecl(nsDependentAtomString(attrName), uriStr,
+                          aOriginalElement);
       }
     }
   }
   return skipAttr;
 }
 
 
 PRBool
@@ -814,17 +814,17 @@ nsXMLContentSerializer::SerializeAttribu
                                             nsAString& aTagPrefix,
                                             const nsAString& aTagNamespaceURI,
                                             nsIAtom* aTagName,
                                             nsAString& aStr,
                                             PRUint32 aSkipAttr,
                                             PRBool aAddNSAttr)
 {
 
-  nsAutoString nameStr, prefixStr, uriStr, valueStr;
+  nsAutoString prefixStr, uriStr, valueStr;
   nsAutoString xmlnsStr;
   xmlnsStr.AssignLiteral(kXMLNS);
   PRUint32 index, count;
 
   // If we had to add a new namespace declaration, serialize
   // and push it on the namespace stack
   if (aAddNSAttr) {
     if (aTagPrefix.IsEmpty()) {
@@ -862,17 +862,17 @@ nsXMLContentSerializer::SerializeAttribu
 
     PRBool addNSAttr = PR_FALSE;
     if (kNameSpaceID_XMLNS != namespaceID) {
       nsContentUtils::NameSpaceManager()->GetNameSpaceURI(namespaceID, uriStr);
       addNSAttr = ConfirmPrefix(prefixStr, uriStr, aOriginalElement, PR_TRUE);
     }
     
     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
     //     invalid XML. see Bug 475518
     if (!nameStr.IsEmpty() && nameStr.First() == '-')
       continue;
 
     PRBool isJS = IsJavaScript(aContent, attrName, namespaceID, valueStr);
--- a/content/events/src/nsDOMEvent.cpp
+++ b/content/events/src/nsDOMEvent.cpp
@@ -245,19 +245,17 @@ NS_METHOD nsDOMEvent::GetType(nsAString&
   }
   const char* name = GetEventName(mEvent->message);
 
   if (name) {
     CopyASCIItoUTF16(name, 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;
   }
   
   return NS_ERROR_FAILURE;
 }
 
 static nsresult
--- a/content/events/src/nsEventListenerManager.cpp
+++ b/content/events/src/nsEventListenerManager.cpp
@@ -1479,20 +1479,18 @@ nsEventListenerManager::GetListenerInfo(
                                     allowsUntrusted, systemGroup);
           NS_ENSURE_TRUE(info, NS_ERROR_OUT_OF_MEMORY);
           aList->AppendObject(info);
         }
       }
     } 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<nsEventListenerInfo> info =
           new nsEventListenerInfo(eventType, ls.mListener, capturing,
                                   allowsUntrusted, systemGroup);
         NS_ENSURE_TRUE(info, NS_ERROR_OUT_OF_MEMORY);
         aList->AppendObject(info);
       }
     } else {
       // Handle normal events.
--- a/content/html/content/src/nsGenericHTMLElement.cpp
+++ b/content/html/content/src/nsGenericHTMLElement.cpp
@@ -2994,22 +2994,20 @@ nsGenericHTMLElement::PerformAccesskey(P
 }
 
 const nsAttrName*
 nsGenericHTMLElement::InternalGetExistingAttrNameFromQName(const nsAString& aStr) const
 {
   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
 nsGenericHTMLElement::GetEditor(nsIEditor** aEditor)
 {
   *aEditor = nsnull;
 
   if (!nsContentUtils::IsCallerTrustedForWrite())
--- a/content/html/document/src/nsHTMLContentSink.cpp
+++ b/content/html/document/src/nsHTMLContentSink.cpp
@@ -420,17 +420,16 @@ HTMLContentSink::AddAttributes(const nsI
 
   if (ac == 0) {
     // No attributes, nothing to do. Do an early return to avoid
     // constructing the nsAutoString object for nothing.
 
     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
   // source.  What we want to happen if a single attribute is set multiple
   // times on an element is that the first time should "win".  That is, <input
   // value="foo" value="bar"> should show "foo".  So we loop over the
   // attributes backwards; this ensures that the first attribute in the set
   // wins.  This does mean that we do some extra work in the case when the same
@@ -449,25 +448,22 @@ HTMLContentSink::AddAttributes(const nsI
     limit = ac;
     step = 1;
   } else {
     i = ac - 1;
     limit = -1;
     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);
-
-    nsCOMPtr<nsIAtom> keyAtom = do_GetAtom(k);
+    nsContentUtils::ASCIIToLower(aNode.GetKeyAt(i), key);
+
+    nsCOMPtr<nsIAtom> keyAtom = do_GetAtom(key);
 
     if (aCheckIfPresent && aContent->HasAttr(kNameSpaceID_None, keyAtom)) {
       continue;
     }
 
     // Get value and remove mandatory quotes
     static const char* kWhitespace = "\n\r\t\b";
 
--- a/content/smil/nsSMILAnimationController.cpp
+++ b/content/smil/nsSMILAnimationController.cpp
@@ -638,19 +638,18 @@ nsSMILAnimationController::GetTargetIden
   // Look up target (animated) attribute-type
   nsSMILTargetAttrType attributeType = aAnimElem->GetTargetAttributeType();
 
   // Check if an 'auto' attributeType refers to a CSS property or XML attribute.
   // Note that SMIL requires we search for CSS properties first. So if they
   // 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);
   }
 
   // Construct the key
   aResult.mElement = targetElem;
   aResult.mAttributeName = attributeName;
--- a/content/smil/nsSMILCompositor.cpp
+++ b/content/smil/nsSMILCompositor.cpp
@@ -144,19 +144,18 @@ nsSMILCompositor::ClearAnimationEffects(
 }
 
 // Protected Helper Functions
 // --------------------------
 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());
     }
   } else {
     return mKey.mElement->GetAnimatedAttr(mKey.mAttributeName);
   }
   return nsnull;
 }
--- a/content/svg/content/src/nsSVGElement.cpp
+++ b/content/svg/content/src/nsSVGElement.cpp
@@ -1082,26 +1082,23 @@ nsSVGElement::UpdateContentStyleRule()
       }
       if (!declaration->InitializeEmpty()) {
         NS_WARNING("could not initialize nsCSSDeclaration");
         declaration->RuleAbort();  // deletes declaration
         return;
       }
     }
 
-    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) {
     nsresult rv = NS_NewCSSStyleRule(getter_AddRefs(mContentStyleRule),
                                      nsnull, declaration);
     if (NS_FAILED(rv)) {
       NS_WARNING("could not create contentstylerule");
       declaration->RuleAbort();  // deletes declaration
@@ -1731,20 +1728,19 @@ nsSVGElement::ParseIntegerOptionalIntege
   return NS_OK;
 }
 
 nsresult
 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));
 }
 
 void
 nsSVGElement::RecompileScriptEventListeners()
 {
--- a/content/svg/content/src/nsSVGLength.cpp
+++ b/content/svg/content/src/nsSVGLength.cpp
@@ -337,19 +337,17 @@ nsSVGLength::GetValueAsString(nsAString 
     case SVG_LENGTHTYPE_PERCENTAGE:
       UnitAtom = nsGkAtoms::percentage;
       break;
     default:
       NS_NOTREACHED("Unknown unit");
       return NS_ERROR_UNEXPECTED;
   }
 
-  nsAutoString unitString;
-  UnitAtom->ToString(unitString);
-  aValueAsString.Append(unitString);
+  aValueAsString.Append(nsDependentAtomString(UnitAtom));
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsSVGLength::SetValueAsString(const nsAString & aValueAsString)
 {
   nsresult rv = NS_OK;
--- a/content/xbl/src/nsXBLBinding.cpp
+++ b/content/xbl/src/nsXBLBinding.cpp
@@ -846,19 +846,16 @@ nsXBLBinding::InstallEventHandlers()
         // Fetch the event type.
         nsCOMPtr<nsIAtom> eventAtom = curr->GetEventName();
         if (!eventAtom ||
             eventAtom == nsGkAtoms::keyup ||
             eventAtom == nsGkAtoms::keydown ||
             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.
 
         // This is a weak ref. systemEventGroup above is already a
         // strong ref, so we are guaranteed it will not go away.
         nsIDOMEventGroup* eventGroup = nsnull;
         if ((curr->GetType() & (NS_HANDLER_TYPE_XBL_COMMAND | NS_HANDLER_TYPE_SYSTEM)) &&
             (isChromeBinding || mBoundElement->IsInNativeAnonymousSubtree())) {
@@ -874,17 +871,19 @@ nsXBLBinding::InstallEventHandlers()
             NS_EVENT_FLAG_CAPTURE : NS_EVENT_FLAG_BUBBLE;
 
           PRBool hasAllowUntrustedAttr = curr->HasAllowUntrustedAttr();
           if ((hasAllowUntrustedAttr && curr->AllowUntrustedEvents()) ||
               (!hasAllowUntrustedAttr && !isChromeDoc)) {
             flags |= NS_PRIV_EVENT_UNTRUSTED_PERMITTED;
           }
 
-          manager->AddEventListenerByType(handler, type, flags, eventGroup);
+          manager->AddEventListenerByType(handler,
+                                          nsDependentAtomString(eventAtom),
+                                          flags, eventGroup);
         }
       }
 
       const nsCOMArray<nsXBLKeyEventHandler>* keyHandlers =
         mPrototypeBinding->GetKeyEventHandlers();
       PRInt32 i;
       for (i = 0; i < keyHandlers->Count(); ++i) {
         nsXBLKeyEventHandler* handler = keyHandlers->ObjectAt(i);
@@ -1010,19 +1009,16 @@ nsXBLBinding::UnhookEventHandlers()
       
       nsCOMPtr<nsIAtom> eventAtom = curr->GetEventName();
       if (!eventAtom ||
           eventAtom == nsGkAtoms::keyup ||
           eventAtom == nsGkAtoms::keydown ||
           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;
 
       // If this is a command, remove it from the system event group,
       // otherwise remove it from the standard event group.
 
       // This is a weak ref. systemEventGroup above is already a
@@ -1030,17 +1026,19 @@ nsXBLBinding::UnhookEventHandlers()
       nsIDOMEventGroup* eventGroup = nsnull;
       if ((curr->GetType() & (NS_HANDLER_TYPE_XBL_COMMAND | NS_HANDLER_TYPE_SYSTEM)) &&
           (isChromeBinding || mBoundElement->IsInNativeAnonymousSubtree())) {
         if (!systemEventGroup)
           manager->GetSystemEventGroupLM(getter_AddRefs(systemEventGroup));
         eventGroup = systemEventGroup;
       }
 
-      manager->RemoveEventListenerByType(handler, type, flags, eventGroup);
+      manager->RemoveEventListenerByType(handler,
+                                         nsDependentAtomString(eventAtom),
+                                         flags, eventGroup);
     }
 
     const nsCOMArray<nsXBLKeyEventHandler>* keyHandlers =
       mPrototypeBinding->GetKeyEventHandlers();
     PRInt32 i;
     for (i = 0; i < keyHandlers->Count(); ++i) {
       nsXBLKeyEventHandler* handler = keyHandlers->ObjectAt(i);
 
--- a/content/xbl/src/nsXBLPrototypeHandler.cpp
+++ b/content/xbl/src/nsXBLPrototypeHandler.cpp
@@ -255,21 +255,18 @@ nsXBLPrototypeHandler::ExecuteHandler(ns
   // event at the element.  It will take care of retargeting it to its
   // command element, if applicable, and executing the event handler.
   if (isXULKey) {
     return DispatchXULKeyCommand(aEvent);
   }
 
   // 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<nsIAtom> onEventAtom = do_GetAtom(onEvent);
+  nsCOMPtr<nsIAtom> onEventAtom = do_GetAtom(NS_LITERAL_STRING("onxbl") +
+                                             nsDependentAtomString(mEventName));
 
   // Compile the event handler.
   PRUint32 stID = nsIProgrammingLanguage::JAVASCRIPT;
 
   // Compile the handler and bind it to the element.
   nsCOMPtr<nsIScriptGlobalObject> boundGlobal;
   nsCOMPtr<nsPIWindowRoot> winRoot(do_QueryInterface(aTarget));
   nsCOMPtr<nsPIDOMWindow> window;
@@ -437,20 +434,17 @@ nsXBLPrototypeHandler::DispatchXBLComman
   }
 
   NS_LossyConvertUTF16toASCII command(mHandlerText);
   if (windowRoot)
     windowRoot->GetControllerForCommand(command.get(), getter_AddRefs(controller));
   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
     // certain times.
 
     nsCOMPtr<nsPIDOMWindow> windowToCheck;
     if (windowRoot)
       windowToCheck = windowRoot->GetWindow();
--- a/content/xslt/src/xpath/txExprLexer.cpp
+++ b/content/xslt/src/xpath/txExprLexer.cpp
@@ -174,27 +174,27 @@ txExprLexer::parse(const nsASingleFragme
           // eat wildcard for NameTest, bail for var ref at COLON
           ++mPosition;
         }
         else {
           --mPosition; // step back
         }
       }
       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 {
           // XXX QUESTION: spec is not too precise
           // badops is sure an error, but is bad:ops, too? We say yes!
           return NS_ERROR_XPATH_OPERATOR_EXPECTED;
         }
       }
--- a/content/xslt/src/xpath/txFunctionCall.cpp
+++ b/content/xslt/src/xpath/txFunctionCall.cpp
@@ -141,25 +141,25 @@ FunctionCall::argsSensitiveTo(ContextSen
     return PR_FALSE;
 }
 
 #ifdef TX_TO_STRING
 void
 FunctionCall::toString(nsAString& aDest)
 {
     nsCOMPtr<nsIAtom> 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(','));
         }
         mParams[i]->toString(aDest);
     }
     aDest.Append(PRUnichar(')'));
 }
--- a/content/xslt/src/xpath/txMozillaXPathTreeWalker.cpp
+++ b/content/xslt/src/xpath/txMozillaXPathTreeWalker.cpp
@@ -822,23 +822,23 @@ nsresult
 txXPathNativeNode::getNode(const txXPathNode& aNode, nsIDOMNode** aResult)
 {
     if (!aNode.isAttribute()) {
         return CallQueryInterface(aNode.mNode, 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<nsIDOMElement> element = do_QueryInterface(aNode.mNode);
     nsCOMPtr<nsIDOMAttr> attr;
-    element->GetAttributeNodeNS(namespaceURI, localname,
+    element->GetAttributeNodeNS(namespaceURI,
+                                nsDependentAtomString(name->LocalName()),
                                 getter_AddRefs(attr));
 
     return CallQueryInterface(attr, aResult);
 }
 
 /* static */
 nsIContent*
 txXPathNativeNode::getContent(const txXPathNode& aNode)
--- a/content/xslt/src/xslt/txUnknownHandler.cpp
+++ b/content/xslt/src/xslt/txUnknownHandler.cpp
@@ -94,19 +94,19 @@ txUnknownHandler::startElement(nsIAtom* 
     }
 
     PRBool htmlRoot = aNsID == kNameSpaceID_None && !aPrefix &&
                       aLowercaseLocalName == txHTMLAtoms::html;
 
     // 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,
                                            aLowercaseLocalName, aNsID);
 
     delete this;
 
     return rv;
--- a/content/xul/content/src/nsXULElement.cpp
+++ b/content/xul/content/src/nsXULElement.cpp
@@ -1156,28 +1156,27 @@ nsXULElement::ParseAttribute(PRInt32 aNa
     }
 
     return PR_TRUE;
 }
 
 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;
     }
 
     if (mPrototype) {
         PRUint32 i;
         for (i = 0; i < mPrototype->mNumAttributes; ++i) {
             attrName = &mPrototype->mAttributes[i].mName;
-            if (attrName->QualifiedNameEquals(name)) {
+            if (attrName->QualifiedNameEquals(aStr)) {
                 return attrName;
             }
         }
     }
 
     return nsnull;
 }
 
@@ -1315,21 +1314,19 @@ nsXULElement::UnsetAttr(PRInt32 aNameSpa
     }
 
     PRBool hasMutationListeners = aNotify &&
         nsContentUtils::HasMutationListeners(this,
             NS_EVENT_BITS_MUTATION_ATTRMODIFIED, this);
 
     nsCOMPtr<nsIDOMAttr> 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();
     if (slots && slots->mAttributeMap) {
       slots->mAttributeMap->DropAttribute(aNameSpaceID, aName);
     }
 
     nsAttrValue ignored;
--- a/content/xul/document/src/nsXULDocument.cpp
+++ b/content/xul/document/src/nsXULDocument.cpp
@@ -1066,22 +1066,18 @@ nsXULDocument::AttributeChanged(nsIDocum
     CheckBroadcasterHookup(aElement, &listener, &resolved);
 
     // See if there is anything we need to persist in the localstore.
     //
     // XXX Namespace handling broken :-(
     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;
         }
     }
 }
 
 void
 nsXULDocument::ContentAppended(nsIDocument* aDocument,
@@ -4181,27 +4177,22 @@ nsXULDocument::BroadcasterHookup::~Broad
             mObservesElement->GetAttr(kNameSpaceID_None, nsGkAtoms::element, broadcasterID);
             mObservesElement->GetAttr(kNameSpaceID_None, nsGkAtoms::attribute, attribute);
         }
         else {
             mObservesElement->GetAttr(kNameSpaceID_None, nsGkAtoms::observes, broadcasterID);
             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()));
     }
 #endif
 }
 
 
 //----------------------------------------------------------------------
@@ -4361,27 +4352,22 @@ nsXULDocument::CheckBroadcasterHookup(ns
     if (PR_LOG_TEST(gXULLog, PR_LOG_NOTICE)) {
         nsCOMPtr<nsIContent> content =
             do_QueryInterface(listener);
 
         NS_ASSERTION(content != nsnull, "not an nsIContent");
         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()));
     }
 #endif
 
     *aNeedsHookup = PR_FALSE;
     *aDidResolve = PR_TRUE;
     return NS_OK;
--- a/content/xul/templates/src/nsXULContentUtils.cpp
+++ b/content/xul/templates/src/nsXULContentUtils.cpp
@@ -390,23 +390,18 @@ nsXULContentUtils::MakeElementID(nsIDocu
 nsresult
 nsXULContentUtils::GetResource(PRInt32 aNameSpaceID, nsIAtom* aAttribute, nsIRDFResource** aResult)
 {
     // construct a fully-qualified URI from the namespace/tag pair.
     NS_PRECONDITION(aAttribute != nsnull, "null ptr");
     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);
 }
 
 
 nsresult
 nsXULContentUtils::GetResource(PRInt32 aNameSpaceID, const nsAString& aAttribute, nsIRDFResource** aResult)
 {
     // construct a fully-qualified URI from the namespace/tag pair.
 
--- a/content/xul/templates/src/nsXULTemplateQueryProcessorRDF.cpp
+++ b/content/xul/templates/src/nsXULTemplateQueryProcessorRDF.cpp
@@ -647,19 +647,19 @@ nsXULTemplateQueryProcessorRDF::Translat
     *aRef = refresult;
     NS_ADDREF(*aRef);
 
     return NS_OK;
 }
 
 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);
 
     *aResult = 0;
 
     // for natural order sorting, use the index in the RDF container for the
     // order. If there is no container, just sort them arbitrarily.
@@ -668,18 +668,17 @@ nsXULTemplateQueryProcessorRDF::CompareR
         PRInt32 leftindex = GetContainerIndexOf(aLeft);
         PRInt32 rightindex = GetContainerIndexOf(aRight);
         *aResult = leftindex == rightindex ? 0 :
                    leftindex > rightindex ? 1 :
                    -1;
         return NS_OK;
     }
 
-    nsAutoString sortkey;
-    aVar->ToString(sortkey);
+    nsDependentAtomString sortkey(aVar);
 
     nsCOMPtr<nsISupports> leftNode, rightNode;
 
     if (!sortkey.IsEmpty() && sortkey[0] != '?' &&
         !StringBeginsWith(sortkey, NS_LITERAL_STRING("rdf:")) &&
         mDB) {
         // if the sort key is not a template variable, it should be an RDF
         // predicate. Get the targets and compare those instead.
--- a/layout/base/nsCSSFrameConstructor.cpp
+++ b/layout/base/nsCSSFrameConstructor.cpp
@@ -9108,19 +9108,17 @@ nsCSSFrameConstructor::ProcessChildren(n
                  (AnyKidsNeedBlockParent(aFrameItems.FirstChild()) != nsnull),
                "Something went awry in our block parent calculations");
 
   if (aFrame->IsBoxFrame() && itemsToConstruct.AnyItemsNeedBlockParent()) {
     // XXXbz we could do this on the FrameConstructionItemList level,
     // 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();
     const char *message =
       (display->mDisplay == NS_STYLE_DISPLAY_INLINE_BOX)
         ? "NeededToWrapXULInlineBox" : "NeededToWrapXUL";
     nsContentUtils::ReportToConsole(nsContentUtils::eXUL_PROPERTIES,
                                     message,
--- a/layout/inspector/src/inDOMView.cpp
+++ b/layout/inspector/src/inDOMView.cpp
@@ -694,18 +694,17 @@ inDOMView::AttributeChanged(nsIDocument 
   if (!(mWhatToShow & nsIDOMNodeFilter::SHOW_ATTRIBUTE)) {
     return;
   }
 
   // get the dom attribute node, if there is any
   nsCOMPtr<nsIDOMNode> content(do_QueryInterface(aContent));
   nsCOMPtr<nsIDOMElement> el(do_QueryInterface(aContent));
   nsCOMPtr<nsIDOMAttr> domAttr;
-  nsAutoString attrStr;
-  aAttribute->ToString(attrStr);
+  nsDependentAtomString attrStr(aAttribute);
   if (aNameSpaceID) {
     nsCOMPtr<nsINameSpaceManager> nsm =
       do_GetService(NS_NAMESPACEMANAGER_CONTRACTID);
     if (!nsm) {
       // we can't find out which attribute we want :(
       return;
     }
     nsString attrNS;
--- a/layout/style/nsCSSRules.cpp
+++ b/layout/style/nsCSSRules.cpp
@@ -1436,20 +1436,17 @@ CSSNameSpaceRuleImpl::GetType(PRUint16* 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 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);
   aCssText.Append(NS_LITERAL_STRING(");"));
   return NS_OK;
 }
 
 NS_IMETHODIMP
--- a/layout/style/nsCSSStyleRule.cpp
+++ b/layout/style/nsCSSStyleRule.cpp
@@ -590,19 +590,18 @@ nsCSSSelector::AppendToStringWithoutComb
       aString.Append(PRUnichar('|'));
       wroteNamespace = PR_TRUE;
     } else if (mNameSpace != kNameSpaceID_Unknown) {
       NS_ASSERTION(CanBeNamespaced(aIsNegated),
                    "How did we end up with this namespace?");
       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 {
       // A selector for an element in any namespace, while the default
       // namespace is something else.  :not() is special in that the default
       // namespace is not implied for non-type selectors, so if this is a
       // negated non-type selector we don't need to output an explicit wildcard
       // namespace here, since those default to a wildcard namespace.
--- a/layout/style/nsCSSStyleSheet.cpp
+++ b/layout/style/nsCSSStyleSheet.cpp
@@ -370,53 +370,47 @@ nsMediaQueryResultCacheKey::Matches(nsPr
   }
 
   return PR_TRUE;
 }
 
 void
 nsMediaQuery::AppendToString(nsAString& aString) const
 {
-  nsAutoString buffer;
-
   if (mHadUnknownExpression) {
     aString.AppendLiteral("not all");
     return;
   }
 
   NS_ASSERTION(!mNegated || !mHasOnly, "can't have not and only");
   NS_ASSERTION(!mTypeOmitted || (!mNegated && !mHasOnly),
                "can't have not or only when type is omitted");
   if (!mTypeOmitted) {
     if (mNegated) {
       aString.AppendLiteral("not ");
     } 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) {
     if (i > 0 || !mTypeOmitted)
       aString.AppendLiteral(" and ");
     aString.AppendLiteral("(");
 
     const nsMediaExpression &expr = mExpressions[i];
     if (expr.mRange == nsMediaExpression::eMin) {
       aString.AppendLiteral("min-");
     } else if (expr.mRange == nsMediaExpression::eMax) {
       aString.AppendLiteral("max-");
     }
 
     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(": ");
       switch (feature->mValueType) {
         case nsMediaFeature::eLength:
           NS_ASSERTION(expr.mValue.IsLengthUnit(), "bad unit");
           // Use 'width' as a property that takes length values
           // written in the normal way.
@@ -445,25 +439,28 @@ nsMediaQuery::AppendToString(nsAString& 
             nsCSSDeclaration::AppendCSSValueToString(eCSSProperty_z_index,
                                                      array->Item(0), aString);
             aString.AppendLiteral("/");
             nsCSSDeclaration::AppendCSSValueToString(eCSSProperty_z_index,
                                                      array->Item(1), aString);
           }
           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:
           NS_ASSERTION(expr.mValue.GetUnit() == eCSSUnit_Enumerated,
                        "bad unit");
           AppendASCIItoUTF16(
               nsCSSProps::ValueToKeyword(expr.mValue.GetIntValue(),
                                          feature->mData.mKeywordTable),
--- a/layout/xul/base/src/nsSliderFrame.cpp
+++ b/layout/xul/base/src/nsSliderFrame.cpp
@@ -218,19 +218,18 @@ public:
                          PRInt32 aValue,
                          PRBool aUserChanged)
   : mListener(aListener), mWhich(aWhich),
     mValue(aValue), mUserChanged(aUserChanged)
   {}
 
   NS_IMETHODIMP Run()
   {
-    nsAutoString which;
-    mWhich->ToString(which);
-    return mListener->ValueChanged(which, mValue, mUserChanged);
+    return mListener->ValueChanged(nsDependentAtomString(mWhich),
+                                   mValue, mUserChanged);
   }
 
   nsCOMPtr<nsISliderListener> mListener;
   nsCOMPtr<nsIAtom> mWhich;
   PRInt32 mValue;
   PRBool mUserChanged;
 };
 
--- a/parser/htmlparser/src/nsParserService.cpp
+++ b/parser/htmlparser/src/nsParserService.cpp
@@ -60,20 +60,17 @@ nsParserService::~nsParserService()
   }
 }
 
 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
 nsParserService::HTMLCaseSensitiveAtomTagToId(nsIAtom* aAtom) const
 {
   return nsHTMLTags::CaseSensitiveLookupTag(aAtom);
 }