From 10e1d18eaf5e1500620c602bfcf6961ba0067cd9 Mon Sep 17 00:00:00 2001 From: "alecf%flett.org" Date: Mon, 23 Jun 2003 18:32:10 +0000 Subject: [PATCH] fix for bug 209780 - do UTF16->UTF8 conversion outside the recursion, so that we don't constantly convert the string we're looking for r=dbaron, sr=jst --- content/html/document/src/nsHTMLDocument.cpp | 4 ++-- content/xml/document/src/nsXMLDocument.cpp | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/content/html/document/src/nsHTMLDocument.cpp b/content/html/document/src/nsHTMLDocument.cpp index 0375ba66afba..7a80089f4dca 100644 --- a/content/html/document/src/nsHTMLDocument.cpp +++ b/content/html/document/src/nsHTMLDocument.cpp @@ -162,7 +162,7 @@ IsNamedItem(nsIContent* aContent, nsIAtom *aTag, nsAString& aName); // MatchElementId is defined in nsXMLDocument.cpp nsIContent * -MatchElementId(nsIContent *aContent, const nsAString& aId); +MatchElementId(nsIContent *aContent, const nsACString& aUTF8Id, const nsAString& aId); static NS_DEFINE_CID(kCParserCID, NS_PARSER_CID); @@ -2839,7 +2839,7 @@ nsHTMLDocument::GetElementById(const nsAString& aElementId, "getElementById(\"\") called, fix caller?"); if (mRootContent && !aElementId.IsEmpty()) { - e = MatchElementId(mRootContent, aElementId); + e = MatchElementId(mRootContent, NS_ConvertUCS2toUTF8(aElementId), aElementId); } if (!e) { diff --git a/content/xml/document/src/nsXMLDocument.cpp b/content/xml/document/src/nsXMLDocument.cpp index ab91a08f0484..331801f6e97a 100644 --- a/content/xml/document/src/nsXMLDocument.cpp +++ b/content/xml/document/src/nsXMLDocument.cpp @@ -1001,7 +1001,7 @@ nsXMLDocument::CreateElementNS(const nsAString& aNamespaceURI, // Id attribute matching function used by nsXMLDocument and // nsHTMLDocument. nsIContent * -MatchElementId(nsIContent *aContent, const nsAString& aId) +MatchElementId(nsIContent *aContent, const nsACString& aUTF8Id, const nsAString& aId) { if (aContent->IsContentOfType(nsIContent::eHTML)) { if (aContent->HasAttr(kNameSpaceID_None, nsHTMLAtoms::id)) { @@ -1019,7 +1019,7 @@ MatchElementId(nsIContent *aContent, const nsAString& aId) if (xmlContent) { nsCOMPtr value; if (NS_SUCCEEDED(xmlContent->GetID(getter_AddRefs(value))) && - value && value->Equals(aId)) { + value && value->EqualsUTF8(aUTF8Id)) { return aContent; } } @@ -1032,7 +1032,7 @@ MatchElementId(nsIContent *aContent, const nsAString& aId) nsCOMPtr child; for (i = 0; i < count && result == nsnull; i++) { aContent->ChildAt(i, getter_AddRefs(child)); - result = MatchElementId(child, aId); + result = MatchElementId(child, aUTF8Id, aId); } return result; @@ -1058,7 +1058,9 @@ nsXMLDocument::GetElementById(const nsAString& aElementId, // XXX For now, we do a brute force search of the content tree. // We should come up with a more efficient solution. // Note that content is *not* refcounted here, so do *not* release it! - nsIContent *content = MatchElementId(mRootContent, aElementId); + nsIContent *content = MatchElementId(mRootContent, + NS_ConvertUCS2toUTF8(aElementId), + aElementId); if (!content) { return NS_OK;