Bug 570258: Some more atom usage cleanup. r=jst
authorJonas Sicking <jonas@sicking.cc>
Tue, 08 Jun 2010 16:25:27 -0700
changeset 43337 861329598eedcc95ba8806a429a871f816c0f8a2
parent 43336 145f1c6fac979996db4c502934c121b57e1005fd
child 43338 b391708e95527fd56770a343036d46669220df40
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjst
bugs570258
milestone1.9.3a5pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 570258: Some more atom usage cleanup. r=jst
content/base/src/nsContentUtils.cpp
content/html/document/src/nsHTMLContentSink.cpp
content/html/document/src/nsHTMLFragmentContentSink.cpp
content/svg/content/src/nsSVGTransformListParser.cpp
content/xslt/src/xml/txXMLUtils.cpp
content/xslt/src/xpath/txExprLexer.cpp
docshell/base/nsDocShell.cpp
editor/libeditor/base/ChangeCSSInlineStyleTxn.cpp
editor/libeditor/html/nsHTMLCSSUtils.cpp
netwerk/streamconv/src/nsStreamConverterService.cpp
rdf/base/src/nsRDFContentSink.cpp
rdf/base/src/nsRDFXMLSerializer.cpp
--- a/content/base/src/nsContentUtils.cpp
+++ b/content/base/src/nsContentUtils.cpp
@@ -2194,32 +2194,30 @@ nsContentUtils::SplitExpatName(const PRU
     }
     else {
       *aNameSpaceID = kNameSpaceID_Unknown;
     }
 
     nameStart = (uriEnd + 1);
     if (nameEnd)  {
       const PRUnichar *prefixStart = nameEnd + 1;
-      *aPrefix = NS_NewAtom(NS_ConvertUTF16toUTF8(prefixStart,
-                                                  pos - prefixStart));
+      *aPrefix = NS_NewAtom(Substring(prefixStart, pos));
     }
     else {
       nameEnd = pos;
       *aPrefix = nsnull;
     }
   }
   else {
     *aNameSpaceID = kNameSpaceID_None;
     nameStart = aExpatName;
     nameEnd = pos;
     *aPrefix = nsnull;
   }
-  *aLocalName = NS_NewAtom(NS_ConvertUTF16toUTF8(nameStart,
-                                                 nameEnd - nameStart));
+  *aLocalName = NS_NewAtom(Substring(nameStart, nameEnd));
 }
 
 // static
 nsPresContext*
 nsContentUtils::GetContextForContent(nsIContent* aContent)
 {
   nsIDocument* doc = aContent->GetCurrentDoc();
   if (doc) {
--- a/content/html/document/src/nsHTMLContentSink.cpp
+++ b/content/html/document/src/nsHTMLContentSink.cpp
@@ -524,20 +524,19 @@ already_AddRefed<nsGenericHTMLElement>
 HTMLContentSink::CreateContentObject(const nsIParserNode& aNode,
                                      nsHTMLTag aNodeType)
 {
   // Find/create atom for the tag name
 
   nsCOMPtr<nsINodeInfo> nodeInfo;
 
   if (aNodeType == eHTMLTag_userdefined) {
-    NS_ConvertUTF16toUTF8 tmp(aNode.GetText());
-    ToLowerCase(tmp);
-
-    nsCOMPtr<nsIAtom> name = do_GetAtom(tmp);
+    nsAutoString lower;
+    nsContentUtils::ASCIIToLower(aNode.GetText(), lower);
+    nsCOMPtr<nsIAtom> name = do_GetAtom(lower);
     nodeInfo = mNodeInfoManager->GetNodeInfo(name, nsnull, kNameSpaceID_XHTML);
   }
   else if (mNodeInfoCache[aNodeType]) {
     nodeInfo = mNodeInfoCache[aNodeType];
   }
   else {
     nsIParserService *parserService = nsContentUtils::GetParserService();
     if (!parserService)
--- a/content/html/document/src/nsHTMLFragmentContentSink.cpp
+++ b/content/html/document/src/nsHTMLFragmentContentSink.cpp
@@ -347,20 +347,19 @@ nsHTMLFragmentContentSink::OpenContainer
   if (mProcessing && !mIgnoreContainer) {
     FlushText();
 
     nsIContent *content = nsnull;
 
     nsCOMPtr<nsINodeInfo> nodeInfo;
 
     if (nodeType == eHTMLTag_userdefined) {
-      NS_ConvertUTF16toUTF8 tmp(aNode.GetText());
-      ToLowerCase(tmp);
-
-      nsCOMPtr<nsIAtom> name = do_GetAtom(tmp);
+      nsAutoString lower;
+      nsContentUtils::ASCIIToLower(aNode.GetText(), lower);
+      nsCOMPtr<nsIAtom> name = do_GetAtom(lower);
       nodeInfo = mNodeInfoManager->GetNodeInfo(name, 
                                                nsnull, 
                                                kNameSpaceID_XHTML);
       NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY);
     }
     else if (mNodeInfoCache[nodeType]) {
       nodeInfo = mNodeInfoCache[nodeType];
     }
@@ -442,20 +441,19 @@ nsHTMLFragmentContentSink::AddLeaf(const
 
         nsIParserService* parserService = nsContentUtils::GetParserService();
         if (!parserService)
           return NS_ERROR_OUT_OF_MEMORY;
 
         nsCOMPtr<nsINodeInfo> nodeInfo;
 
         if (nodeType == eHTMLTag_userdefined) {
-          NS_ConvertUTF16toUTF8 tmp(aNode.GetText());
-          ToLowerCase(tmp);
-
-          nsCOMPtr<nsIAtom> name = do_GetAtom(tmp);
+          nsAutoString lower;
+          nsContentUtils::ASCIIToLower(aNode.GetText(), lower);
+          nsCOMPtr<nsIAtom> name = do_GetAtom(lower);
           nodeInfo = mNodeInfoManager->GetNodeInfo(name, nsnull,
                                                    kNameSpaceID_XHTML);
           NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY);
         }
         else if (mNodeInfoCache[nodeType]) {
           nodeInfo = mNodeInfoCache[nodeType];
         }
         else {
@@ -722,36 +720,31 @@ nsHTMLFragmentContentSink::AddAttributes
 
   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;
+  nsAutoString 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
   // attribute is set multiple times, but we save a HasAttr call in the much
   // more common case of reasonable HTML.
 
   for (PRInt32 i = ac - 1; i >= 0; i--) {
     // 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), k);
     nsCOMPtr<nsIAtom> keyAtom = do_GetAtom(k);
 
     // Get value and remove mandatory quotes
     static const char* kWhitespace = "\n\r\t\b";
     const nsAString& v =
       nsContentUtils::TrimCharsInSet(kWhitespace, aNode.GetValueAt(i));
 
     if (nodeType == eHTMLTag_a && keyAtom == nsGkAtoms::name) {
@@ -933,30 +926,27 @@ nsHTMLParanoidFragmentSink::AddAttribute
                                           nsIContent* aContent)
 {
   PRInt32 ac = aNode.GetAttributeCount();
 
   if (ac == 0) {
     return NS_OK;
   }
 
-  nsCAutoString k;
+  nsAutoString k;
   nsHTMLTag nodeType = nsHTMLTag(aNode.GetNodeType());
 
   nsresult rv;
   // use this to check for safe URIs in the few attributes that allow them
   nsIScriptSecurityManager* secMan = nsContentUtils::GetSecurityManager();
   nsCOMPtr<nsIURI> baseURI;
 
   for (PRInt32 i = ac - 1; i >= 0; i--) {
     rv = NS_OK;
-    const nsAString& key = aNode.GetKeyAt(i);
-    CopyUTF16toUTF8(key, k);
-    ToLowerCase(k);
-
+    nsContentUtils::ASCIIToLower(aNode.GetKeyAt(i), k);
     nsCOMPtr<nsIAtom> keyAtom = do_GetAtom(k);
 
     // not an allowed attribute
     if (!sAllowedAttributes || !sAllowedAttributes->GetEntry(keyAtom)) {
       continue;
     }
 
     // Get value and remove mandatory quotes
--- a/content/svg/content/src/nsSVGTransformListParser.cpp
+++ b/content/svg/content/src/nsSVGTransformListParser.cpp
@@ -117,21 +117,22 @@ nsSVGTransformListParser::GetTransformTo
 
   const char* delimiters = "\x20\x9\xD\xA,(";
   char* delimiterStart = PL_strnpbrk(mTokenPos, delimiters, 11);
   if (delimiterStart != 0) {
     /* save this character and null it out */
     char holdingChar = *delimiterStart;
     *delimiterStart = '\0';
 
-    if (mTokenPos != 0 && nsCRT::strlen(mTokenPos) > 0) {
-      *aKeyAtom = NS_NewAtom(mTokenPos);
+    PRUint32 len;
+    if (mTokenPos != 0 && (len = nsCRT::strlen(mTokenPos)) > 0) {
+      *aKeyAtom = NS_NewAtom(Substring(mTokenPos, mTokenPos + len));
 
       if (aAdvancePos) {
-         mInputPos = mTokenPos + nsCRT::strlen(mTokenPos);
+         mInputPos = mTokenPos + len;
          mTokenPos = mInputPos;
       }
     } else {
       rv = NS_ERROR_FAILURE;
     }
     /* reset character back to original */
     *delimiterStart = holdingChar;
   } else {
--- a/content/xslt/src/xml/txXMLUtils.cpp
+++ b/content/xslt/src/xml/txXMLUtils.cpp
@@ -116,36 +116,34 @@ XMLUtils::splitExpatName(const PRUnichar
                                                                     uriEnd));
         if (*aNameSpaceID == kNameSpaceID_Unknown) {
             return NS_ERROR_FAILURE;
         }
 
         nameStart = (uriEnd + 1);
         if (nameEnd)  {
             const PRUnichar *prefixStart = nameEnd + 1;
-            *aPrefix = NS_NewAtom(NS_ConvertUTF16toUTF8(prefixStart,
-                                                        pos - prefixStart));
+            *aPrefix = NS_NewAtom(Substring(prefixStart, pos));
             if (!*aPrefix) {
                 return NS_ERROR_OUT_OF_MEMORY;
             }
         }
         else {
             nameEnd = pos;
             *aPrefix = nsnull;
         }
     }
     else {
         *aNameSpaceID = kNameSpaceID_None;
         nameStart = aExpatName;
         nameEnd = pos;
         *aPrefix = nsnull;
     }
 
-    *aLocalName = NS_NewAtom(NS_ConvertUTF16toUTF8(nameStart,
-                                                   nameEnd - nameStart));
+    *aLocalName = NS_NewAtom(Substring(nameStart, nameEnd));
 
     return *aLocalName ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
 }
 
 nsresult
 XMLUtils::splitQName(const nsAString& aName, nsIAtom** aPrefix,
                      nsIAtom** aLocalName)
 {
--- a/content/xslt/src/xpath/txExprLexer.cpp
+++ b/content/xslt/src/xpath/txExprLexer.cpp
@@ -321,27 +321,27 @@ txExprLexer::parse(const nsASingleFragme
         }
         else {
           newToken = new Token(mPosition, Token::CNAME);
         }
         ++mPosition;
         break;
       case L_PAREN:
         if (prevToken->mType == Token::CNAME) {
-          NS_ConvertUTF16toUTF8 utf8Value(prevToken->Value());
-          if (txXPathAtoms::comment->EqualsUTF8(utf8Value)) {
+          const nsDependentSubstring& val = prevToken->Value();
+          if (val.EqualsLiteral("comment")) {
             prevToken->mType = Token::COMMENT_AND_PAREN;
           }
-          else if (txXPathAtoms::node->EqualsUTF8(utf8Value)) {
+          else if (val.EqualsLiteral("node")) {
             prevToken->mType = Token::NODE_AND_PAREN;
           }
-          else if (txXPathAtoms::processingInstruction->EqualsUTF8(utf8Value)) {
+          else if (val.EqualsLiteral("processing-instruction")) {
             prevToken->mType = Token::PROC_INST_AND_PAREN;
           }
-          else if (txXPathAtoms::text->EqualsUTF8(utf8Value)) {
+          else if (val.EqualsLiteral("text")) {
             prevToken->mType = Token::TEXT_AND_PAREN;
           }
           else {
             prevToken->mType = Token::FUNCTION_NAME_AND_PAREN;
           }
           isToken = PR_FALSE;
         }
         else {
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -364,18 +364,18 @@ ForEachPing(nsIContent *content, ForEach
   //       just parse the raw attribute.  It might be nice if the content node
   //       implemented an interface that exposed an enumeration of nsIURIs.
 
   // Make sure we are dealing with either an <A> or <AREA> element in the HTML
   // or XHTML namespace.
   if (!content->IsHTML())
     return;
   nsIAtom *nameAtom = content->Tag();
-  if (!nameAtom->EqualsUTF8(NS_LITERAL_CSTRING("a")) &&
-      !nameAtom->EqualsUTF8(NS_LITERAL_CSTRING("area")))
+  if (!nameAtom->Equals(NS_LITERAL_STRING("a")) &&
+      !nameAtom->Equals(NS_LITERAL_STRING("area")))
     return;
 
   nsCOMPtr<nsIAtom> pingAtom = do_GetAtom("ping");
   if (!pingAtom)
     return;
 
   nsAutoString value;
   content->GetAttr(kNameSpaceID_None, pingAtom, value);
--- a/editor/libeditor/base/ChangeCSSInlineStyleTxn.cpp
+++ b/editor/libeditor/base/ChangeCSSInlineStyleTxn.cpp
@@ -39,16 +39,17 @@
 #include "ChangeCSSInlineStyleTxn.h"
 #include "nsIDOMElement.h"
 #include "nsIDOMCSSStyleDeclaration.h"
 #include "nsIDOMElementCSSInlineStyle.h"
 #include "nsReadableUtils.h"
 #include "nsUnicharUtils.h"
 #include "nsCRT.h"
 #include "nsIAtom.h"
+#include "nsGkAtoms.h"
 
 #define kNullCh (PRUnichar('\0'))
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(ChangeCSSInlineStyleTxn)
 
 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(ChangeCSSInlineStyleTxn,
                                                 EditTxn)
   NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mElement)
@@ -320,20 +321,17 @@ NS_IMETHODIMP ChangeCSSInlineStyleTxn::G
   aString += tempString;
   return NS_OK;
 }
 
 // answers true if the CSS property accepts more than one value
 PRBool
 ChangeCSSInlineStyleTxn::AcceptsMoreThanOneValue(nsIAtom *aCSSProperty)
 {
-  nsIAtom * textDecorationAtom = NS_NewAtom("text-decoration");
-  PRBool res = (textDecorationAtom == aCSSProperty);
-  NS_IF_RELEASE(textDecorationAtom);
-  return res;
+  return aCSSProperty == nsGkAtoms::text_decoration;
 }
 
 // adds the value aNewValue to the list of white-space separated values aValues
 NS_IMETHODIMP
 ChangeCSSInlineStyleTxn::AddValueToMultivalueProperty(nsAString & aValues, const nsAString & aNewValue)
 {
   if (aValues.IsEmpty()
       || aValues.LowerCaseEqualsLiteral("none")) {
--- a/editor/libeditor/html/nsHTMLCSSUtils.cpp
+++ b/editor/libeditor/html/nsHTMLCSSUtils.cpp
@@ -740,17 +740,16 @@ nsHTMLCSSUtils::ParseLength(const nsAStr
 {
   nsAString::const_iterator iter;
   aString.BeginReading(iter);
 
   float a = 10.0f , b = 1.0f, value = 0;
   PRInt8 sign = 1;
   PRInt32 i = 0, j = aString.Length();
   PRUnichar c;
-  nsAutoString unit;
   PRBool floatingPointFound = PR_FALSE;
   c = *iter;
   if (PRUnichar('-') == c) { sign = -1; iter++; i++; }
   else if (PRUnichar('+') == c) { iter++; i++; }
   while (i < j) {
     c = *iter;
     if ((PRUnichar('0') == c) ||
         (PRUnichar('1') == c) ||
@@ -768,19 +767,18 @@ nsHTMLCSSUtils::ParseLength(const nsAStr
     else if (!floatingPointFound && (PRUnichar('.') == c)) {
       floatingPointFound = PR_TRUE;
       a = 1.0f; b = 0.1f;
     }
     else break;
     iter++;
     i++;
   }
-  unit = Substring(aString, aString.Length() - (j-i), j-i);
   *aValue = value * sign;
-  *aUnit = NS_NewAtom(unit); 
+  *aUnit = NS_NewAtom(StringTail(aString, j-i)); 
 }
 
 void
 nsHTMLCSSUtils::GetCSSPropertyAtom(nsCSSEditableProperty aProperty, nsIAtom ** aAtom)
 {
   *aAtom = nsnull;
   switch (aProperty) {
     case eCSSEditableProperty_background_color:
--- a/netwerk/streamconv/src/nsStreamConverterService.cpp
+++ b/netwerk/streamconv/src/nsStreamConverterService.cpp
@@ -217,17 +217,17 @@ nsStreamConverterService::AddAdjacency(c
         }
         data->data.edges = edgeArray;
         mAdjacencyList->Put(newToKey, data);
     }
     
     // Now we know the FROM and TO types are represented as keys in the hashtable.
     // Let's "connect" the verticies, making an edge.
 
-    nsCOMPtr<nsIAtom> vertex = do_GetAtom(toStr.get()); 
+    nsCOMPtr<nsIAtom> vertex = do_GetAtom(toStr); 
     if (!vertex) return NS_ERROR_OUT_OF_MEMORY;
 
     NS_ASSERTION(fromEdges, "something wrong in adjacency list construction");
     if (!fromEdges)
         return NS_ERROR_FAILURE;
 
     nsCOMArray<nsIAtom> *adjacencyList = fromEdges->data.edges;
     return adjacencyList->AppendObject(vertex) ? NS_OK : NS_ERROR_FAILURE;
--- a/rdf/base/src/nsRDFContentSink.cpp
+++ b/rdf/base/src/nsRDFContentSink.cpp
@@ -1372,18 +1372,17 @@ RDFContentSinkImpl::SplitExpatName(const
             }
 
             uriEnd = pos;
             nameStart = pos + 1;
         }
     }
 
     const nsDependentSubstring& nameSpaceURI = Substring(aExpatName, uriEnd);
-    *aLocalName = NS_NewAtom(NS_ConvertUTF16toUTF8(nameStart,
-                                                   pos - nameStart));
+    *aLocalName = NS_NewAtom(Substring(nameStart, pos));
     return nameSpaceURI;
 }
 
 nsresult
 RDFContentSinkImpl::InitContainer(nsIRDFResource* aContainerType, nsIRDFResource* aContainer)
 {
     // Do the right kind of initialization based on the container
     // 'type' resource, and the state of the container (i.e., 'make' a
--- a/rdf/base/src/nsRDFXMLSerializer.cpp
+++ b/rdf/base/src/nsRDFXMLSerializer.cpp
@@ -216,17 +216,17 @@ rdf_BlockingWrite(nsIOutputStream* strea
 {
     NS_ConvertUTF16toUTF8 utf8(s);
     return rdf_BlockingWrite(stream, utf8.get(), utf8.Length());
 }
 
 already_AddRefed<nsIAtom>
 nsRDFXMLSerializer::EnsureNewPrefix()
 {
-    nsCAutoString qname;
+    nsAutoString qname;
     nsCOMPtr<nsIAtom> prefix;
     PRBool isNewPrefix;
     do {
         isNewPrefix = PR_TRUE;
         qname.AssignLiteral("NS");
         qname.AppendInt(++mPrefixID, 10);
         prefix = do_GetAtom(qname);
         nsNameSpaceMap::const_iterator iter = mNameSpaces.first();