From 523004daf8e76c0e43ff3b9dba6f06b426b7ca64 Mon Sep 17 00:00:00 2001 From: "bryner%brianryner.com" Date: Mon, 24 May 2004 06:10:52 +0000 Subject: [PATCH] Bug 244475, avoid some shared buffer overhead and an extra allocation/copy when looking up attribute name atoms. r+sr=bzbarsky. --- content/html/document/src/nsHTMLContentSink.cpp | 6 ++++-- content/html/document/src/nsHTMLFragmentContentSink.cpp | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/content/html/document/src/nsHTMLContentSink.cpp b/content/html/document/src/nsHTMLContentSink.cpp index 01ba015a0df..155eec556b1 100644 --- a/content/html/document/src/nsHTMLContentSink.cpp +++ b/content/html/document/src/nsHTMLContentSink.cpp @@ -803,7 +803,7 @@ HTMLContentSink::AddAttributes(const nsIParserNode& aNode, return NS_OK; } - nsAutoString k; + nsCAutoString k; nsHTMLTag nodeType = nsHTMLTag(aNode.GetNodeType()); // The attributes are on the parser node in the order they came in in the @@ -818,7 +818,9 @@ HTMLContentSink::AddAttributes(const nsIParserNode& aNode, for (PRInt32 i = ac - 1; i >= 0; i--) { // Get lower-cased key const nsAString& key = aNode.GetKeyAt(i); - k.Assign(key); + // 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 keyAtom = do_GetAtom(k); diff --git a/content/html/document/src/nsHTMLFragmentContentSink.cpp b/content/html/document/src/nsHTMLFragmentContentSink.cpp index 7fa6b5f8604..963cf665ecf 100644 --- a/content/html/document/src/nsHTMLFragmentContentSink.cpp +++ b/content/html/document/src/nsHTMLFragmentContentSink.cpp @@ -864,7 +864,7 @@ nsHTMLFragmentContentSink::AddAttributes(const nsIParserNode& aNode, return NS_OK; } - nsAutoString k; + nsCAutoString k; nsHTMLTag nodeType = nsHTMLTag(aNode.GetNodeType()); // The attributes are on the parser node in the order they came in in the @@ -879,7 +879,9 @@ nsHTMLFragmentContentSink::AddAttributes(const nsIParserNode& aNode, for (PRInt32 i = ac - 1; i >= 0; i--) { // Get lower-cased key const nsAString& key = aNode.GetKeyAt(i); - k.Assign(key); + // 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 keyAtom = do_GetAtom(k);