landing attempt #2 for 195262 - support for static atoms, and converting atoms over to UTF8 to reduce bloat - now without performance regressions!

sr=darin, r=dbaron
This commit is contained in:
alecf%netscape.com 2003-03-25 18:55:59 +00:00
parent 3a7fd80dab
commit 8c50d0242a
60 changed files with 766 additions and 501 deletions

View File

@ -269,7 +269,8 @@ public:
const nsAString& aPrefix, const nsAString& aPrefix,
PRInt32 aNamespaceID) const = 0; PRInt32 aNamespaceID) const = 0;
NS_IMETHOD_(PRBool) NamespaceEquals(const nsAString& aNamespaceURI) const = 0; NS_IMETHOD_(PRBool) NamespaceEquals(const nsAString& aNamespaceURI) const = 0;
NS_IMETHOD_(PRBool) QualifiedNameEquals(const nsAString& aQualifiedName) const = 0; // switch to UTF8 - this allows faster access for consumers
NS_IMETHOD_(PRBool) QualifiedNameEquals(const nsACString& aQualifiedName) const = 0;
/* /*
* This is a convinience method that creates a new nsINodeInfo that differs * This is a convinience method that creates a new nsINodeInfo that differs

View File

@ -2971,7 +2971,7 @@ nsGenericElement::TriggerLink(nsIPresContext* aPresContext,
nsLinkVerb aVerb, nsLinkVerb aVerb,
nsIURI* aBaseURL, nsIURI* aBaseURL,
const nsAString& aURLSpec, const nsAString& aURLSpec,
const nsAFlatString& aTargetSpec, const nsAString& aTargetSpec,
PRBool aClick) PRBool aClick)
{ {
nsCOMPtr<nsILinkHandler> handler; nsCOMPtr<nsILinkHandler> handler;
@ -3006,10 +3006,10 @@ nsGenericElement::TriggerLink(nsIPresContext* aPresContext,
// says it's ok. // says it's ok.
if (NS_SUCCEEDED(proceed)) if (NS_SUCCEEDED(proceed))
handler->OnLinkClick(this, aVerb, targetURI, handler->OnLinkClick(this, aVerb, targetURI,
aTargetSpec.get()); PromiseFlatString(aTargetSpec).get());
} else { } else {
handler->OnOverLink(this, targetURI, handler->OnOverLink(this, targetURI,
aTargetSpec.get()); PromiseFlatString(aTargetSpec).get());
} }
return rv; return rv;
} }
@ -3086,11 +3086,13 @@ struct nsGenericAttribute
: mNodeInfo(aNodeInfo), : mNodeInfo(aNodeInfo),
mValue(aValue) mValue(aValue)
{ {
MOZ_COUNT_CTOR(nsGenericAttribute);
NS_IF_ADDREF(mNodeInfo); NS_IF_ADDREF(mNodeInfo);
} }
~nsGenericAttribute(void) ~nsGenericAttribute(void)
{ {
MOZ_COUNT_DTOR(nsGenericAttribute);
NS_IF_RELEASE(mNodeInfo); NS_IF_RELEASE(mNodeInfo);
} }
@ -3125,11 +3127,12 @@ nsGenericContainerElement::~nsGenericContainerElement()
nsresult nsresult
nsGenericContainerElement::NormalizeAttrString(const nsAString& aStr, nsINodeInfo*& aNodeInfo) nsGenericContainerElement::NormalizeAttrString(const nsAString& aStr, nsINodeInfo*& aNodeInfo)
{ {
NS_ConvertUCS2toUTF8 utf8String(aStr);
if (mAttributes) { if (mAttributes) {
PRInt32 indx, count = mAttributes->Count(); PRInt32 indx, count = mAttributes->Count();
for (indx = 0; indx < count; indx++) { for (indx = 0; indx < count; indx++) {
nsGenericAttribute* attr = (nsGenericAttribute*)mAttributes->ElementAt(indx); nsGenericAttribute* attr = (nsGenericAttribute*)mAttributes->ElementAt(indx);
if (attr->mNodeInfo->QualifiedNameEquals(aStr)) { if (attr->mNodeInfo->QualifiedNameEquals(utf8String)) {
aNodeInfo = attr->mNodeInfo; aNodeInfo = attr->mNodeInfo;
NS_ADDREF(aNodeInfo); NS_ADDREF(aNodeInfo);

View File

@ -63,8 +63,7 @@
#define kGreaterThan NS_LITERAL_STRING(">") #define kGreaterThan NS_LITERAL_STRING(">")
#define kEndTag NS_LITERAL_STRING("</") #define kEndTag NS_LITERAL_STRING("</")
static const PRUnichar kMozStr[] = {'m', 'o', 'z', 0}; static const char kMozStr[] = "moz";
static const PRInt32 kMozStrLength = 3;
static const PRInt32 kLongLineLen = 128; static const PRInt32 kLongLineLen = 128;
@ -256,9 +255,7 @@ nsHTMLContentSerializer::EscapeURI(const nsAString& aURI, nsAString& aEscapedURI
if (mCharSet && !uri.IsASCII()) { if (mCharSet && !uri.IsASCII()) {
const PRUnichar *charset; mCharSet->ToUTF8String(documentCharset);
mCharSet->GetUnicode(&charset);
documentCharset.Adopt(ToNewUTF8String(nsDependentString(charset)));
textToSubURI = do_GetService(NS_ITEXTTOSUBURI_CONTRACTID, &rv); textToSubURI = do_GetService(NS_ITEXTTOSUBURI_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
} }
@ -316,6 +313,8 @@ nsHTMLContentSerializer::SerializeAttributes(nsIContent* aContent,
aContent->GetAttrCount(count); aContent->GetAttrCount(count);
NS_NAMED_LITERAL_STRING(mozStr1, "_moz");
for (index = 0; index < count; index++) { for (index = 0; index < count; index++) {
aContent->GetAttrNameAt(index, aContent->GetAttrNameAt(index,
namespaceID, namespaceID,
@ -323,13 +322,12 @@ nsHTMLContentSerializer::SerializeAttributes(nsIContent* aContent,
*getter_AddRefs(attrPrefix)); *getter_AddRefs(attrPrefix));
// Filter out any attribute starting with [-|_]moz // Filter out any attribute starting with [-|_]moz
const PRUnichar* sharedName; const char* sharedName;
attrName->GetUnicode(&sharedName); attrName->GetUTF8String(&sharedName);
if ((('_' == *sharedName) || ('-' == *sharedName)) && if ((('_' == *sharedName) || ('-' == *sharedName)) &&
!nsCRT::strncmp(sharedName+1, kMozStr, kMozStrLength)) { !nsCRT::strncmp(sharedName+1, kMozStr, sizeof(kMozStr)-1)) {
continue; continue;
} }
aContent->GetAttr(namespaceID, attrName, valueStr); aContent->GetAttr(namespaceID, attrName, valueStr);
// //
@ -338,8 +336,7 @@ nsHTMLContentSerializer::SerializeAttributes(nsIContent* aContent,
// //
if ((aTagName == nsHTMLAtoms::br) && if ((aTagName == nsHTMLAtoms::br) &&
(attrName.get() == nsHTMLAtoms::type) && (attrName.get() == nsHTMLAtoms::type) &&
!valueStr.IsEmpty() && ('_' == valueStr[0]) && (mozStr1.Equals(Substring(valueStr, 0, mozStr1.Length())))) {
!nsCRT::strncmp(valueStr.get()+1, kMozStr, kMozStrLength)) {
continue; continue;
} }
@ -457,9 +454,9 @@ nsHTMLContentSerializer::AppendElementStart(nsIDOMElement *aElement,
AppendToString(kLessThan, aStr); AppendToString(kLessThan, aStr);
const PRUnichar* sharedName; nsAutoString nameStr;
name->GetUnicode(&sharedName); name->ToString(nameStr);
AppendToString(sharedName, -1, aStr); AppendToString(nameStr.get(), -1, aStr);
// Need to keep track of OL and LI elements in order to get ordinal number // Need to keep track of OL and LI elements in order to get ordinal number
// for the LI. // for the LI.
@ -554,13 +551,12 @@ nsHTMLContentSerializer::AppendElementEnd(nsIDOMElement *aElement,
} }
} }
const PRUnichar* sharedName; nsAutoString nameStr;
name->GetUnicode(&sharedName); name->ToString(nameStr);
nsIParserService* parserService = nsContentUtils::GetParserServiceWeakRef(); nsIParserService* parserService = nsContentUtils::GetParserServiceWeakRef();
if (parserService && (name.get() != nsHTMLAtoms::style)) { if (parserService && (name.get() != nsHTMLAtoms::style)) {
nsAutoString nameStr(sharedName);
PRBool isContainer; PRBool isContainer;
PRInt32 id; PRInt32 id;
@ -582,7 +578,7 @@ nsHTMLContentSerializer::AppendElementEnd(nsIDOMElement *aElement,
EndIndentation(name, hasDirtyAttr, aStr); EndIndentation(name, hasDirtyAttr, aStr);
AppendToString(kEndTag, aStr); AppendToString(kEndTag, aStr);
AppendToString(sharedName, -1, aStr); AppendToString(nameStr.get(), -1, aStr);
AppendToString(kGreaterThan, aStr); AppendToString(kGreaterThan, aStr);
if (LineBreakAfterClose(name, hasDirtyAttr)) { if (LineBreakAfterClose(name, hasDirtyAttr)) {

View File

@ -107,8 +107,8 @@ nsNodeInfo::GetQualifiedName(nsAString& aQualifiedName) const
aQualifiedName.Truncate(); aQualifiedName.Truncate();
} }
const PRUnichar *name; nsAutoString name;
mInner.mName->GetUnicode(&name); mInner.mName->ToString(name);
aQualifiedName.Append(name); aQualifiedName.Append(name);
@ -183,20 +183,14 @@ nsNodeInfo::GetNodeInfoManager(nsINodeInfoManager*& aNodeInfoManager) const
NS_IMETHODIMP_(PRBool) NS_IMETHODIMP_(PRBool)
nsNodeInfo::Equals(const nsAString& aName) const nsNodeInfo::Equals(const nsAString& aName) const
{ {
const PRUnichar *name; return mInner.mName->Equals(aName);
mInner.mName->GetUnicode(&name);
return aName.Equals(name);
} }
NS_IMETHODIMP_(PRBool) NS_IMETHODIMP_(PRBool)
nsNodeInfo::Equals(const nsAString& aName, const nsAString& aPrefix) const nsNodeInfo::Equals(const nsAString& aName, const nsAString& aPrefix) const
{ {
const PRUnichar *name; if (!mInner.mName->Equals(aName)) {
mInner.mName->GetUnicode(&name);
if (!aName.Equals(name)) {
return PR_FALSE; return PR_FALSE;
} }
@ -204,19 +198,15 @@ nsNodeInfo::Equals(const nsAString& aName, const nsAString& aPrefix) const
return aPrefix.IsEmpty(); return aPrefix.IsEmpty();
} }
mInner.mPrefix->GetUnicode(&name); return mInner.mPrefix->Equals(aPrefix);
return aPrefix.Equals(name);
} }
NS_IMETHODIMP_(PRBool) NS_IMETHODIMP_(PRBool)
nsNodeInfo::Equals(const nsAString& aName, PRInt32 aNamespaceID) const nsNodeInfo::Equals(const nsAString& aName, PRInt32 aNamespaceID) const
{ {
const PRUnichar *name; return mInner.mNamespaceID == aNamespaceID &&
mInner.mName->GetUnicode(&name); mInner.mName->Equals(aName);
return aName.Equals(name) && (mInner.mNamespaceID == aNamespaceID);
} }
@ -225,15 +215,13 @@ nsNodeInfo::Equals(const nsAString& aName, const nsAString& aPrefix,
PRInt32 aNamespaceID) const PRInt32 aNamespaceID) const
{ {
PRUnichar nullChar = '\0'; PRUnichar nullChar = '\0';
const PRUnichar *name, *prefix = &nullChar;
mInner.mName->GetUnicode(&name);
if (mInner.mPrefix) { if (!mInner.mNamespaceID == aNamespaceID ||
mInner.mPrefix->GetUnicode(&prefix); !mInner.mName->Equals(aName))
} return PR_FALSE;
return ((mInner.mNamespaceID == aNamespaceID) && aName.Equals(name) && return mInner.mPrefix ? mInner.mPrefix->Equals(aPrefix) :
aPrefix.Equals(prefix)); aPrefix.IsEmpty();
} }
@ -246,26 +234,22 @@ nsNodeInfo::NamespaceEquals(const nsAString& aNamespaceURI) const
return nsINodeInfo::NamespaceEquals(nsid); return nsINodeInfo::NamespaceEquals(nsid);
} }
NS_IMETHODIMP_(PRBool) NS_IMETHODIMP_(PRBool)
nsNodeInfo::QualifiedNameEquals(const nsAString& aQualifiedName) const nsNodeInfo::QualifiedNameEquals(const nsACString& aQualifiedName) const
{ {
const PRUnichar *name;
mInner.mName->GetUnicode(&name); if (!mInner.mPrefix)
return mInner.mName->EqualsUTF8(aQualifiedName);
if (!mInner.mPrefix) { nsACString::const_iterator start;
return aQualifiedName.Equals(name);
}
nsAString::const_iterator start;
aQualifiedName.BeginReading(start); aQualifiedName.BeginReading(start);
nsAString::const_iterator colon(start); nsACString::const_iterator colon(start);
const PRUnichar *prefix; const char* prefix;
mInner.mPrefix->GetUnicode(&prefix); mInner.mPrefix->GetUTF8String(&prefix);
PRUint32 len = nsCRT::strlen(prefix); PRUint32 len = strlen(prefix);
if (len >= aQualifiedName.Length()) { if (len >= aQualifiedName.Length()) {
return PR_FALSE; return PR_FALSE;
@ -280,18 +264,17 @@ nsNodeInfo::QualifiedNameEquals(const nsAString& aQualifiedName) const
} }
// Compare the prefix to the string from the start to the colon // Compare the prefix to the string from the start to the colon
if (!Substring(start, colon).Equals(prefix)) { if (!mInner.mPrefix->EqualsUTF8(Substring(start, colon)))
return PR_FALSE; return PR_FALSE;
}
++colon; // Skip the ':' ++colon; // Skip the ':'
nsAString::const_iterator end; nsACString::const_iterator end;
aQualifiedName.EndReading(end); aQualifiedName.EndReading(end);
// Compare the local name to the string between the colon and the // Compare the local name to the string between the colon and the
// end of aQualifiedName // end of aQualifiedName
return Substring(colon, end).Equals(name); return mInner.mName->EqualsUTF8(Substring(colon, end));
} }
NS_IMETHODIMP NS_IMETHODIMP

View File

@ -66,7 +66,7 @@ public:
NS_IMETHOD_(PRBool) Equals(const nsAString& aName, const nsAString& aPrefix, NS_IMETHOD_(PRBool) Equals(const nsAString& aName, const nsAString& aPrefix,
PRInt32 aNamespaceID) const; PRInt32 aNamespaceID) const;
NS_IMETHOD_(PRBool) NamespaceEquals(const nsAString& aNamespaceURI) const; NS_IMETHOD_(PRBool) NamespaceEquals(const nsAString& aNamespaceURI) const;
NS_IMETHOD_(PRBool) QualifiedNameEquals(const nsAString& aQualifiedName) const; NS_IMETHOD_(PRBool) QualifiedNameEquals(const nsACString& aQualifiedName) const;
NS_IMETHOD NameChanged(nsIAtom *aName, nsINodeInfo*& aResult); NS_IMETHOD NameChanged(nsIAtom *aName, nsINodeInfo*& aResult);
NS_IMETHOD PrefixChanged(nsIAtom *aPrefix, nsINodeInfo*& aResult); NS_IMETHOD PrefixChanged(nsIAtom *aPrefix, nsINodeInfo*& aResult);

View File

@ -1807,8 +1807,8 @@ nsPlainTextSerializer::GetAttributeValue(const nsIParserNode* aNode,
} }
} }
else if (aNode) { else if (aNode) {
const PRUnichar *name; nsAutoString name;
aName->GetUnicode(&name); aName->ToString(name);
PRInt32 count = aNode->GetAttributeCount(); PRInt32 count = aNode->GetAttributeCount();
for (PRInt32 i=0;i<count;i++) { for (PRInt32 i=0;i<count;i++) {

View File

@ -1862,10 +1862,8 @@ nsGenericHTMLElement::SetAttr(nsINodeInfo* aNodeInfo,
PRBool nsGenericHTMLElement::IsEventName(nsIAtom* aName) PRBool nsGenericHTMLElement::IsEventName(nsIAtom* aName)
{ {
const PRUnichar *name = nsnull; const char* name;
aName->GetUTF8String(&name);
aName->GetUnicode(&name);
NS_ASSERTION(name, "Null string in atom!");
if (name[0] != 'o' || name[1] != 'n') { if (name[0] != 'o' || name[1] != 'n') {
return PR_FALSE; return PR_FALSE;

View File

@ -397,6 +397,8 @@ public:
nsString mBaseTarget; nsString mBaseTarget;
nsICSSLoader *mCSSLoader; nsICSSLoader *mCSSLoader;
// depth of containment within <noembed>, <noframes> etc
PRInt32 mInsideNoXXXTag; PRInt32 mInsideNoXXXTag;
PRInt32 mInMonolithicContainer; PRInt32 mInMonolithicContainer;
PRUint32 mFlags; PRUint32 mFlags;
@ -1031,11 +1033,7 @@ NS_CreateHTMLElement(nsIHTMLContent** aResult, nsINodeInfo *aNodeInfo,
parserService->HTMLIdToStringTag(id, &tag); parserService->HTMLIdToStringTag(id, &tag);
NS_ASSERTION(tag, "What? Reverse mapping of id to string broken!!!"); NS_ASSERTION(tag, "What? Reverse mapping of id to string broken!!!");
const PRUnichar *name_str = nsnull; if (!name->Equals(nsDependentString(tag))) {
name->GetUnicode(&name_str);
NS_ASSERTION(name_str, "What? No string in atom?!?");
if (nsCRT::strcmp(tag, name_str) != 0) {
nsCOMPtr<nsIAtom> atom = do_GetAtom(tag); nsCOMPtr<nsIAtom> atom = do_GetAtom(tag);
rv = aNodeInfo->NameChanged(atom, *getter_AddRefs(kungFuDeathGrip)); rv = aNodeInfo->NameChanged(atom, *getter_AddRefs(kungFuDeathGrip));
@ -1710,14 +1708,13 @@ SinkContext::CloseContainer(const nsHTMLTag aTag)
// Tracing code // Tracing code
nsCOMPtr<nsIAtom> tag; nsCOMPtr<nsIAtom> tag;
mStack[mStackPos].mContent->GetTag(*getter_AddRefs(tag)); mStack[mStackPos].mContent->GetTag(*getter_AddRefs(tag));
const PRUnichar* tagChar; const char *tagStr;
tag->GetUnicode(&tagChar); tag->GetUTF8String(&tagStr);
nsDependentString str(tagChar);
SINK_TRACE(SINK_TRACE_REFLOW, SINK_TRACE(SINK_TRACE_REFLOW,
("SinkContext::CloseContainer: reflow on notifyImmediate " ("SinkContext::CloseContainer: reflow on notifyImmediate "
"tag=%s newIndex=%d stackPos=%d", "tag=%s newIndex=%d stackPos=%d",
NS_LossyConvertUCS2toASCII(str).get(), tagStr,
mStack[mStackPos].mNumFlushed, mStackPos)); mStack[mStackPos].mNumFlushed, mStackPos));
#endif #endif
mSink->NotifyAppend(content, mStack[mStackPos].mNumFlushed); mSink->NotifyAppend(content, mStack[mStackPos].mNumFlushed);
@ -2117,13 +2114,12 @@ SinkContext::FlushTags(PRBool aNotify)
// Tracing code // Tracing code
nsCOMPtr<nsIAtom> tag; nsCOMPtr<nsIAtom> tag;
mStack[stackPos].mContent->GetTag(*getter_AddRefs(tag)); mStack[stackPos].mContent->GetTag(*getter_AddRefs(tag));
const PRUnichar* tagChar; const char* tagStr;
tag->GetUnicode(&tagChar); tag->GetUTF8String(&tagStr);
nsDependentString str(tagChar);
SINK_TRACE(SINK_TRACE_REFLOW, SINK_TRACE(SINK_TRACE_REFLOW,
("SinkContext::FlushTags: tag=%s from newindex=%d at " ("SinkContext::FlushTags: tag=%s from newindex=%d at "
"stackPos=%d", NS_LossyConvertUCS2toASCII(str).get(), "stackPos=%d", tagStr,
mStack[stackPos].mNumFlushed, stackPos)); mStack[stackPos].mNumFlushed, stackPos));
#endif #endif
if ((mStack[stackPos].mInsertionPoint != -1) && if ((mStack[stackPos].mInsertionPoint != -1) &&
@ -5259,12 +5255,11 @@ HTMLContentSink::ProcessHeaderData(nsIAtom* aHeader, const nsAString& aValue,
if (NS_SUCCEEDED(mParser->GetChannel(getter_AddRefs(channel)))) { if (NS_SUCCEEDED(mParser->GetChannel(getter_AddRefs(channel)))) {
nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(channel)); nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(channel));
if (httpChannel) { if (httpChannel) {
const PRUnichar *header = 0; const char* header;
(void)aHeader->GetUnicode(&header); (void)aHeader->GetUTF8String(&header);
(void)httpChannel->SetResponseHeader( (void)httpChannel->SetResponseHeader(nsDependentCString(header),
NS_ConvertUCS2toUTF8(header), NS_ConvertUCS2toUTF8(aValue),
NS_ConvertUCS2toUTF8(aValue), PR_TRUE);
PR_TRUE);
} }
} }
} }

View File

@ -1569,9 +1569,10 @@ static PRBool IsTreePseudoElement(const nsString& aPseudo)
static PRBool IsTreePseudoElement(nsIAtom* aPseudo) static PRBool IsTreePseudoElement(nsIAtom* aPseudo)
{ {
nsAutoString str; const char* str;
aPseudo->ToString(str); aPseudo->GetUTF8String(&str);
return Substring(str, 0, 11).Equals(NS_LITERAL_STRING(":-moz-tree-")); static const char moz_tree[] = ":-moz-tree-";
return nsCRT::strncmp(str, moz_tree, PRInt32(sizeof(moz_tree)-1)) == 0;
} }
#endif #endif

View File

@ -584,8 +584,8 @@ PRInt32 nsCSSSelector::CalcWeight(void) const
static PRBool IsPseudoElement(nsIAtom* aAtom) static PRBool IsPseudoElement(nsIAtom* aAtom)
{ {
if (aAtom) { if (aAtom) {
const PRUnichar *str; const char* str;
aAtom->GetUnicode(&str); aAtom->GetUTF8String(&str);
return str && (*str == ':'); return str && (*str == ':');
} }
@ -604,7 +604,7 @@ void nsCSSSelector::AppendNegationToString(nsAString& aString)
nsresult nsCSSSelector::ToString( nsAString& aString, nsICSSStyleSheet* aSheet, PRBool aIsPseudoElem, nsresult nsCSSSelector::ToString( nsAString& aString, nsICSSStyleSheet* aSheet, PRBool aIsPseudoElem,
PRInt8 aNegatedIndex) const PRInt8 aNegatedIndex) const
{ {
const PRUnichar* temp; nsAutoString temp;
PRBool aIsNegated = PRBool(0 < aNegatedIndex); PRBool aIsNegated = PRBool(0 < aNegatedIndex);
// selectors are linked from right-to-left, so the next selector in the linked list // selectors are linked from right-to-left, so the next selector in the linked list
@ -631,8 +631,8 @@ nsresult nsCSSSelector::ToString( nsAString& aString, nsICSSStyleSheet* aSheet,
// will return null if namespace was the default // will return null if namespace was the default
sheetNS->FindNameSpacePrefix(mNameSpace, *getter_AddRefs(prefixAtom)); sheetNS->FindNameSpacePrefix(mNameSpace, *getter_AddRefs(prefixAtom));
if (prefixAtom) { if (prefixAtom) {
const PRUnichar* prefix; nsAutoString prefix;
prefixAtom->GetUnicode(&prefix); prefixAtom->ToString(prefix);
aString.Append(prefix); aString.Append(prefix);
aString.Append(PRUnichar('|')); aString.Append(PRUnichar('|'));
} }
@ -648,15 +648,16 @@ nsresult nsCSSSelector::ToString( nsAString& aString, nsICSSStyleSheet* aSheet,
} else { } else {
// Append the tag name, if there is one // Append the tag name, if there is one
if (mTag) { if (mTag) {
mTag->GetUnicode(&temp); nsAutoString prefix;
aString.Append(temp); mTag->ToString(prefix);
aString.Append(prefix);
NS_IF_NEGATED_END(aIsNegated, aString) NS_IF_NEGATED_END(aIsNegated, aString)
} }
// Append the id, if there is one // Append the id, if there is one
if (mIDList) { if (mIDList) {
nsAtomList* list = mIDList; nsAtomList* list = mIDList;
while (list != nsnull) { while (list != nsnull) {
list->mAtom->GetUnicode(&temp); list->mAtom->ToString(temp);
NS_IF_NEGATED_START(aIsNegated, aString) NS_IF_NEGATED_START(aIsNegated, aString)
aString.Append(PRUnichar('#')); aString.Append(PRUnichar('#'));
aString.Append(temp); aString.Append(temp);
@ -668,7 +669,7 @@ nsresult nsCSSSelector::ToString( nsAString& aString, nsICSSStyleSheet* aSheet,
if (mClassList) { if (mClassList) {
nsAtomList* list = mClassList; nsAtomList* list = mClassList;
while (list != nsnull) { while (list != nsnull) {
list->mAtom->GetUnicode(&temp); list->mAtom->ToString(temp);
NS_IF_NEGATED_START(aIsNegated, aString) NS_IF_NEGATED_START(aIsNegated, aString)
aString.Append(PRUnichar('.')); aString.Append(PRUnichar('.'));
aString.Append(temp); aString.Append(temp);
@ -692,14 +693,14 @@ nsresult nsCSSSelector::ToString( nsAString& aString, nsICSSStyleSheet* aSheet,
// will return null if namespace was the default // will return null if namespace was the default
sheetNS->FindNameSpacePrefix(list->mNameSpace, *getter_AddRefs(prefixAtom)); sheetNS->FindNameSpacePrefix(list->mNameSpace, *getter_AddRefs(prefixAtom));
if (prefixAtom) { if (prefixAtom) {
const PRUnichar* prefix; nsAutoString prefix;
prefixAtom->GetUnicode(&prefix); prefixAtom->ToString(prefix);
aString.Append(prefix); aString.Append(prefix);
aString.Append(PRUnichar('|')); aString.Append(PRUnichar('|'));
} }
} }
// Append the attribute name // Append the attribute name
list->mAttr->GetUnicode(&temp); list->mAttr->ToString(temp);
aString.Append(temp); aString.Append(temp);
// Append the function // Append the function
if (list->mFunction == NS_ATTR_FUNC_EQUALS) { if (list->mFunction == NS_ATTR_FUNC_EQUALS) {
@ -732,7 +733,7 @@ nsresult nsCSSSelector::ToString( nsAString& aString, nsICSSStyleSheet* aSheet,
if (mPseudoClassList) { if (mPseudoClassList) {
nsAtomStringList* list = mPseudoClassList; nsAtomStringList* list = mPseudoClassList;
while (list != nsnull) { while (list != nsnull) {
list->mAtom->GetUnicode(&temp); list->mAtom->ToString(temp);
NS_IF_NEGATED_START(aIsNegated, aString) NS_IF_NEGATED_START(aIsNegated, aString)
aString.Append(temp); aString.Append(temp);
if (nsnull != list->mString) { if (nsnull != list->mString) {

View File

@ -168,12 +168,11 @@ RuleHash_CIMatchEntry(PLDHashTable *table, const PLDHashEntryHdr *hdr,
if (match_atom == entry_atom) if (match_atom == entry_atom)
return PR_TRUE; return PR_TRUE;
const PRUnichar *match_str, *entry_str; const char *match_str, *entry_str;
match_atom->GetUnicode(&match_str); match_atom->GetUTF8String(&match_str);
entry_atom->GetUnicode(&entry_str); entry_atom->GetUTF8String(&entry_str);
return nsDependentString(match_str).Equals(nsDependentString(entry_str), return (nsCRT::strcasecmp(entry_str, match_str) == 0);
nsCaseInsensitiveStringComparator());
} }
PR_STATIC_CALLBACK(PRBool) PR_STATIC_CALLBACK(PRBool)
@ -1116,8 +1115,8 @@ DOMMediaListImpl::GetText(nsAString& aMediaText)
QueryElementAt(index++, NS_GET_IID(nsIAtom), getter_AddRefs(medium)); QueryElementAt(index++, NS_GET_IID(nsIAtom), getter_AddRefs(medium));
NS_ENSURE_TRUE(medium, NS_ERROR_FAILURE); NS_ENSURE_TRUE(medium, NS_ERROR_FAILURE);
const PRUnichar *buffer; nsAutoString buffer;
medium->GetUnicode(&buffer); medium->ToString(buffer);
aMediaText.Append(buffer); aMediaText.Append(buffer);
if (index < count) { if (index < count) {
aMediaText.Append(NS_LITERAL_STRING(", ")); aMediaText.Append(NS_LITERAL_STRING(", "));
@ -1234,8 +1233,8 @@ DOMMediaListImpl::Item(PRUint32 aIndex, nsAString& aReturn)
nsCOMPtr<nsIAtom> medium(do_QueryInterface(tmp)); nsCOMPtr<nsIAtom> medium(do_QueryInterface(tmp));
NS_ENSURE_TRUE(medium, NS_ERROR_FAILURE); NS_ENSURE_TRUE(medium, NS_ERROR_FAILURE);
const PRUnichar *buffer; nsAutoString buffer;
medium->GetUnicode(&buffer); medium->ToString(buffer);
aReturn.Assign(buffer); aReturn.Assign(buffer);
} else { } else {
aReturn.Truncate(); aReturn.Truncate();
@ -3742,15 +3741,15 @@ static PRBool SelectorMatches(RuleProcessorData &data,
IDList = IDList->mNext; IDList = IDList->mNext;
} while (IDList); } while (IDList);
} else { } else {
const PRUnichar* id1Str; const char* id1Str;
data.mContentID->GetUnicode(&id1Str); data.mContentID->GetUTF8String(&id1Str);
nsDependentString id1(id1Str); nsDependentCString id1(id1Str);
do { do {
const PRUnichar* id2Str; const char* id2Str;
IDList->mAtom->GetUnicode(&id2Str); IDList->mAtom->GetUTF8String(&id2Str);
nsDependentString id2(id2Str); nsDependentCString id2(id2Str);
if (localTrue != if (localTrue !=
id1.Equals(id2, nsCaseInsensitiveStringComparator())) { id1.Equals(id2, nsCaseInsensitiveCStringComparator())) {
result = PR_FALSE; result = PR_FALSE;
break; break;
} }

View File

@ -1376,17 +1376,15 @@ nsHTMLAttributes::HasClass(nsIAtom* aClass, PRBool aCaseSensitive) const
classList = classList->mNext; classList = classList->mNext;
} while (classList); } while (classList);
} else { } else {
const PRUnichar* class1Buf; const char* class1;
aClass->GetUnicode(&class1Buf); aClass->GetUTF8String(&class1);
// This length calculation (and the |aCaseSensitive| check above) could // This length calculation (and the |aCaseSensitive| check above) could
// theoretically be pulled out of another loop by creating a separate // theoretically be pulled out of another loop by creating a separate
// |HasClassCI| function. // |HasClassCI| function.
nsDependentString class1(class1Buf);
do { do {
const PRUnichar* class2Buf; const char* class2;
classList->mAtom->GetUnicode(&class2Buf); classList->mAtom->GetUTF8String(&class2);
nsDependentString class2(class2Buf); if (nsCRT::strcasecmp(class1, class2) == 0)
if (class1.Equals(class2, nsCaseInsensitiveStringComparator()))
return PR_TRUE; return PR_TRUE;
classList = classList->mNext; classList = classList->mNext;
} while (classList); } while (classList);

View File

@ -768,9 +768,10 @@ nsSVGAttributes::NormalizeAttrString(const nsAString& aStr,
nsINodeInfo*& aNodeInfo) nsINodeInfo*& aNodeInfo)
{ {
PRInt32 indx, count = Count(); PRInt32 indx, count = Count();
NS_ConvertUCS2toUTF8 utf8String(aStr);
for (indx = 0; indx < count; indx++) { for (indx = 0; indx < count; indx++) {
nsSVGAttribute* attr = ElementAt(indx); nsSVGAttribute* attr = ElementAt(indx);
if (attr->GetNodeInfo()->QualifiedNameEquals(aStr)) { if (attr->GetNodeInfo()->QualifiedNameEquals(utf8String)) {
aNodeInfo = attr->GetNodeInfo(); aNodeInfo = attr->GetNodeInfo();
NS_ADDREF(aNodeInfo); NS_ADDREF(aNodeInfo);

View File

@ -93,26 +93,22 @@ NS_NewXMLElement(nsIContent** aInstancePtrResult, nsINodeInfo *aNodeInfo)
return NS_OK; return NS_OK;
} }
static nsIAtom* kSimpleAtom; // XXX these should get moved to nsXMLAtoms
static nsIAtom* kHrefAtom; static nsIAtom* kHrefAtom;
static nsIAtom* kShowAtom; static nsIAtom* kShowAtom;
static nsIAtom* kTypeAtom; static nsIAtom* kTypeAtom;
static nsIAtom* kBaseAtom; static nsIAtom* kBaseAtom;
static nsIAtom* kActuateAtom; static nsIAtom* kActuateAtom;
static nsIAtom* kOnLoadAtom;
static nsIAtom* kEmbedAtom; static nsIAtom* kEmbedAtom;
static PRUint32 kElementCount; static PRUint32 kElementCount;
nsXMLElement::nsXMLElement() : mIsLink(PR_FALSE) nsXMLElement::nsXMLElement() : mIsLink(PR_FALSE)
{ {
if (0 == kElementCount++) { if (0 == kElementCount++) {
kSimpleAtom = NS_NewAtom("simple");
kHrefAtom = NS_NewAtom("href"); kHrefAtom = NS_NewAtom("href");
kShowAtom = NS_NewAtom("show"); kShowAtom = NS_NewAtom("show");
kTypeAtom = NS_NewAtom("type"); kTypeAtom = NS_NewAtom("type");
kBaseAtom = NS_NewAtom("base"); kBaseAtom = NS_NewAtom("base");
kActuateAtom = NS_NewAtom("actuate"); kActuateAtom = NS_NewAtom("actuate");
kOnLoadAtom = NS_NewAtom("onLoad");
kEmbedAtom = NS_NewAtom("embed"); kEmbedAtom = NS_NewAtom("embed");
} }
} }
@ -120,13 +116,11 @@ nsXMLElement::nsXMLElement() : mIsLink(PR_FALSE)
nsXMLElement::~nsXMLElement() nsXMLElement::~nsXMLElement()
{ {
if (0 == --kElementCount) { if (0 == --kElementCount) {
NS_RELEASE(kSimpleAtom);
NS_RELEASE(kHrefAtom); NS_RELEASE(kHrefAtom);
NS_RELEASE(kShowAtom); NS_RELEASE(kShowAtom);
NS_RELEASE(kTypeAtom); NS_RELEASE(kTypeAtom);
NS_RELEASE(kBaseAtom); NS_RELEASE(kBaseAtom);
NS_RELEASE(kActuateAtom); NS_RELEASE(kActuateAtom);
NS_RELEASE(kOnLoadAtom);
NS_RELEASE(kEmbedAtom); NS_RELEASE(kEmbedAtom);
} }
} }
@ -321,17 +315,12 @@ nsXMLElement::SetAttr(nsINodeInfo *aNodeInfo,
NS_ENSURE_ARG_POINTER(aNodeInfo); NS_ENSURE_ARG_POINTER(aNodeInfo);
if (aNodeInfo->Equals(kTypeAtom, kNameSpaceID_XLink)) { if (aNodeInfo->Equals(kTypeAtom, kNameSpaceID_XLink)) {
const PRUnichar* simpleStr;
kSimpleAtom->GetUnicode(&simpleStr); // NOTE: This really is a link according to the XLink spec,
if (aValue.Equals(simpleStr)) { // we do not need to check other attributes. If there
// NOTE: This really is a link according to the XLink spec, // is no href attribute, then this link is simply
// we do not need to check other attributes. If there // untraversible [XLink 3.2].
// is no href attribute, then this link is simply mIsLink = aValue.Equals(NS_LITERAL_STRING("simple"));
// untraversible [XLink 3.2].
mIsLink = PR_TRUE;
} else {
mIsLink = PR_FALSE;
}
// We will check for actuate="onLoad" in MaybeTriggerAutoLink // We will check for actuate="onLoad" in MaybeTriggerAutoLink
} }
@ -408,10 +397,7 @@ nsXMLElement::MaybeTriggerAutoLink(nsIWebShell *aShell)
nsresult rv = NS_OK; nsresult rv = NS_OK;
if (mIsLink) { if (mIsLink) {
// preload and precalculate length of atom outside of loop NS_NAMED_LITERAL_STRING(onloadString, "onLoad");
const PRUnichar *onloadUnicode;
kOnLoadAtom->GetUnicode(&onloadUnicode);
nsDependentString onloadString(onloadUnicode);
do { do {
// actuate="onLoad" ? // actuate="onLoad" ?
nsAutoString value; nsAutoString value;

View File

@ -1177,7 +1177,6 @@ nsXMLContentSink::ProcessHeaderData(nsIAtom* aHeader,const nsAString& aValue,nsI
rv = originalCodebase->GetURI(getter_AddRefs(codebaseURI)); rv = originalCodebase->GetURI(getter_AddRefs(codebaseURI));
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
char *cookie = ToNewUTF8String(aValue);
nsCOMPtr<nsIScriptGlobalObject> globalObj; nsCOMPtr<nsIScriptGlobalObject> globalObj;
nsCOMPtr<nsIPrompt> prompt; nsCOMPtr<nsIPrompt> prompt;
mDocument->GetScriptGlobalObject(getter_AddRefs(globalObj)); mDocument->GetScriptGlobalObject(getter_AddRefs(globalObj));
@ -1196,8 +1195,8 @@ nsXMLContentSink::ProcessHeaderData(nsIAtom* aHeader,const nsAString& aValue,nsI
} }
} }
rv = cookieServ->SetCookieString(codebaseURI, prompt, cookie, httpChannel); rv = cookieServ->SetCookieString(codebaseURI, prompt, NS_ConvertUCS2toUTF8(aValue).get(), httpChannel);
nsCRT::free(cookie);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
} // END set-cookie } // END set-cookie
else if (aHeader == nsHTMLAtoms::link) { else if (aHeader == nsHTMLAtoms::link) {
@ -1223,12 +1222,11 @@ nsXMLContentSink::ProcessHeaderData(nsIAtom* aHeader,const nsAString& aValue,nsI
if (NS_SUCCEEDED(mParser->GetChannel(getter_AddRefs(channel)))) { if (NS_SUCCEEDED(mParser->GetChannel(getter_AddRefs(channel)))) {
nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(channel)); nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(channel));
if (httpChannel) { if (httpChannel) {
const PRUnichar *header = 0; const char *header = 0;
(void)aHeader->GetUnicode(&header); (void)aHeader->GetUTF8String(&header);
(void)httpChannel->SetResponseHeader( (void)httpChannel->SetResponseHeader(nsDependentCString(header),
NS_ConvertUCS2toUTF8(header), NS_ConvertUCS2toUTF8(aValue),
NS_ConvertUCS2toUTF8(aValue), PR_TRUE);
PR_TRUE);
} }
} }
} }

View File

@ -946,11 +946,8 @@ MatchId(nsIContent *aContent, const nsAString& aName)
nsCOMPtr<nsIXMLContent> xmlContent = do_QueryInterface(aContent); nsCOMPtr<nsIXMLContent> xmlContent = do_QueryInterface(aContent);
nsCOMPtr<nsIAtom> IDValue; nsCOMPtr<nsIAtom> IDValue;
if (xmlContent && NS_SUCCEEDED(xmlContent->GetID(*getter_AddRefs(IDValue))) && IDValue) { if (xmlContent && NS_SUCCEEDED(xmlContent->GetID(*getter_AddRefs(IDValue))) && IDValue) {
const PRUnichar* IDValStr = nsnull; if (IDValue->Equals(aName))
IDValue->GetUnicode(&IDValStr);
if (aName.Equals(IDValStr)) {
return aContent; return aContent;
}
} }
} }

View File

@ -2388,11 +2388,13 @@ nsXULElement::NormalizeAttrString(const nsAString& aStr,
nsINodeInfo*& aNodeInfo) nsINodeInfo*& aNodeInfo)
{ {
PRInt32 i, count = Attributes() ? Attributes()->Count() : 0; PRInt32 i, count = Attributes() ? Attributes()->Count() : 0;
NS_ConvertUCS2toUTF8 utf8String(aStr);
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
nsXULAttribute* attr = NS_REINTERPRET_CAST(nsXULAttribute*, nsXULAttribute* attr = NS_REINTERPRET_CAST(nsXULAttribute*,
Attributes()->ElementAt(i)); Attributes()->ElementAt(i));
nsINodeInfo *ni = attr->GetNodeInfo(); nsINodeInfo *ni = attr->GetNodeInfo();
if (ni->QualifiedNameEquals(aStr)) { if (ni->QualifiedNameEquals(utf8String)) {
aNodeInfo = ni; aNodeInfo = ni;
NS_ADDREF(aNodeInfo); NS_ADDREF(aNodeInfo);
@ -2405,7 +2407,7 @@ nsXULElement::NormalizeAttrString(const nsAString& aStr,
nsXULPrototypeAttribute* attr = &(mPrototype->mAttributes[i]); nsXULPrototypeAttribute* attr = &(mPrototype->mAttributes[i]);
nsINodeInfo *ni = attr->mNodeInfo; nsINodeInfo *ni = attr->mNodeInfo;
if (ni->QualifiedNameEquals(aStr)) { if (ni->QualifiedNameEquals(utf8String)) {
aNodeInfo = ni; aNodeInfo = ni;
NS_ADDREF(aNodeInfo); NS_ADDREF(aNodeInfo);

View File

@ -374,9 +374,7 @@ XULContentSinkImpl::~XULContentSinkImpl()
nsAutoString prefix; nsAutoString prefix;
if (prefixAtom) if (prefixAtom)
{ {
const PRUnichar *unicodeString; prefixAtom->ToString(prefix);
prefixAtom->GetUnicode(&unicodeString);
prefix = unicodeString;
} }
else else
{ {

View File

@ -2030,8 +2030,6 @@ nsXULDocument::ExecuteOnBroadcastHandlerFor(nsIContent* aBroadcaster,
// Now we execute the onchange handler in the context of the // Now we execute the onchange handler in the context of the
// observer. We need to find the observer in order to // observer. We need to find the observer in order to
// execute the handler. // execute the handler.
nsAutoString attrName;
aAttr->ToString(attrName);
nsCOMPtr<nsIContent> listener = do_QueryInterface(aListener); nsCOMPtr<nsIContent> listener = do_QueryInterface(aListener);
PRInt32 count; PRInt32 count;
@ -2065,7 +2063,7 @@ nsXULDocument::ExecuteOnBroadcastHandlerFor(nsIContent* aBroadcaster,
child->GetAttr(kNameSpaceID_None, nsXULAtoms::attribute, child->GetAttr(kNameSpaceID_None, nsXULAtoms::attribute,
listeningToAttribute); listeningToAttribute);
if (listeningToAttribute != attrName && if (!aAttr->Equals(listeningToAttribute) &&
listeningToAttribute != NS_LITERAL_STRING("*")) { listeningToAttribute != NS_LITERAL_STRING("*")) {
continue; continue;
} }
@ -3072,13 +3070,13 @@ nsXULDocument::Persist(nsIContent* aElement, PRInt32 aNameSpaceID,
// Ick. Construct a property from the attribute. Punt on // Ick. Construct a property from the attribute. Punt on
// namespaces for now. // namespaces for now.
const PRUnichar* attrstr; const char* attrstr;
rv = aAttribute->GetUnicode(&attrstr); rv = aAttribute->GetUTF8String(&attrstr);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIRDFResource> attr; nsCOMPtr<nsIRDFResource> attr;
rv = gRDFService->GetUnicodeResource(nsDependentString(attrstr), rv = gRDFService->GetResource(nsDependentCString(attrstr),
getter_AddRefs(attr)); getter_AddRefs(attr));
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
// Turn the value into a literal // Turn the value into a literal

View File

@ -184,14 +184,14 @@ nsContentTestNode::FilterInstantiations(InstantiationSet& aInstantiations, void*
if (tag != mTag) { if (tag != mTag) {
consistent = PR_FALSE; consistent = PR_FALSE;
const PRUnichar *expected, *actual; const char *expected, *actual;
mTag->GetUnicode(&expected); mTag->GetUTF8String(&expected);
tag->GetUnicode(&actual); tag->GetUTF8String(&actual);
PR_LOG(gXULTemplateLog, PR_LOG_DEBUG, PR_LOG(gXULTemplateLog, PR_LOG_DEBUG,
(" => tag mismatch; expected %s, actual %s", (" => tag mismatch; expected %s, actual %s",
NS_LossyConvertUCS2toASCII(expected).get(), expected,
NS_LossyConvertUCS2toASCII(actual).get())); actual));
} }
} }

View File

@ -908,14 +908,14 @@ AtomToEventHandlerName(nsIAtom *aName, char *charName, PRUint32 charNameSize)
// optimized to avoid ns*Str*.h explicit/implicit copying and malloc'ing // optimized to avoid ns*Str*.h explicit/implicit copying and malloc'ing
// even nsCAutoString may call an Append that copy-constructs an nsStr from // even nsCAutoString may call an Append that copy-constructs an nsStr from
// a const PRUnichar* // a const PRUnichar*
const PRUnichar *name; const char *name;
aName->GetUnicode(&name); aName->GetUTF8String(&name);
char c; char c;
PRUint32 i = 0; PRUint32 i = 0;
do { do {
NS_ASSERTION(name[i] < 128, "non-ASCII event handler name"); NS_ASSERTION(name[i] < 128, "non-ASCII event handler name");
c = char(name[i]); c = name[i];
// The HTML content sink must have folded to lowercase already. // The HTML content sink must have folded to lowercase already.
NS_ASSERTION(c == '\0' || isalpha(c), "non-alphabetic event handler name"); NS_ASSERTION(c == '\0' || isalpha(c), "non-alphabetic event handler name");

View File

@ -3587,9 +3587,9 @@ nsEditor::NodeIsType(nsIDOMNode *aNode, nsIAtom *aTag)
{ {
nsAutoString tag; nsAutoString tag;
element->GetTagName(tag); element->GetTagName(tag);
const PRUnichar *unicodeString; const char *tagStr;
aTag->GetUnicode(&unicodeString); aTag->GetUTF8String(&tagStr);
if (tag.Equals(unicodeString, nsCaseInsensitiveStringComparator())) if (tag.EqualsIgnoreCase(tagStr))
{ {
return PR_TRUE; return PR_TRUE;
} }

View File

@ -503,7 +503,7 @@ function onselect_loadURI(tree, columnName) {
function getPropertyValue(properties, propName) { function getPropertyValue(properties, propName) {
for (var i=0; i< properties.Count(); ++i) { for (var i=0; i< properties.Count(); ++i) {
var atom = properties.GetElementAt(i).QueryInterface(Components.interfaces.nsIAtom); var atom = properties.GetElementAt(i).QueryInterface(Components.interfaces.nsIAtom);
var atomValue = atom.GetUnicode(); var atomValue = atom.toString();
if (atomValue.substr(0, propName.length) == propName) if (atomValue.substr(0, propName.length) == propName)
return atomValue.substr(propName.length); return atomValue.substr(propName.length);
} }

View File

@ -178,7 +178,7 @@ XBLBindings.prototype =
while (urls.hasMoreElements()) { while (urls.hasMoreElements()) {
var item = urls.getNext(); var item = urls.getNext();
var url = item.QueryInterface(Components.interfaces.nsIAtom).GetUnicode(); var url = item.QueryInterface(Components.interfaces.nsIAtom).toString();
var menu = document.createElement("menuitem"); var menu = document.createElement("menuitem");
menu.setAttribute("value", url); menu.setAttribute("value", url);
menu.setAttribute("label", url); menu.setAttribute("label", url);

View File

@ -73,9 +73,7 @@ void TX_ToLowerCase(const nsAString& aSource, nsAString& aDest);
*/ */
static PRBool TX_StringEqualsAtom(const nsAString& aString, nsIAtom* aAtom) static PRBool TX_StringEqualsAtom(const nsAString& aString, nsIAtom* aAtom)
{ {
const PRUnichar* atom; return aAtom->Equals(aString);
aAtom->GetUnicode(&atom);
return aString.Equals(atom);
}; };
#endif // txStringUtils_h__ #endif // txStringUtils_h__

View File

@ -88,12 +88,12 @@ double txNameTest::getDefaultPriority()
void txNameTest::toString(nsAString& aDest) void txNameTest::toString(nsAString& aDest)
{ {
if (mPrefix) { if (mPrefix) {
const PRUnichar* prefix; nsAutoString prefix;
mPrefix->GetUnicode(&prefix); mPrefix->ToString(prefix);
aDest.Append(nsDependentString(prefix)); aDest.Append(prefix);
aDest.Append(PRUnichar(':')); aDest.Append(PRUnichar(':'));
} }
const PRUnichar* localName; nsAutoString localName;
mLocalName->GetUnicode(&localName); mLocalName->ToString(localName);
aDest.Append(nsDependentString(localName)); aDest.Append(localName);
} }

View File

@ -174,13 +174,11 @@ NS_IMETHODIMP nsFontMetricsBeOS::Init(const nsFont& aFont, nsIAtom* aLangGroup,
// family is generic string like // family is generic string like
// "serif" "sans-serif" "cursive" "fantasy" "monospace" "-moz-fixed" // "serif" "sans-serif" "cursive" "fantasy" "monospace" "-moz-fixed"
// so look up preferences and get real family name // so look up preferences and get real family name
const PRUnichar *langGroup; const char *lang;
aLangGroup->GetUnicode( &langGroup ); aLangGroup->GetUTF8String( &lang );
char *lang = ToNewUTF8String(nsDependentString(langGroup));
char prop[256]; char prop[256];
sprintf( prop, "font.name.%s.%s", family, lang ); sprintf( prop, "font.name.%s.%s", family, lang );
nsMemory::Free(lang);
nsMemory::Free(family); nsMemory::Free(family);
// look up prefs // look up prefs

View File

@ -620,9 +620,9 @@ static nsFontPropertyName gWeightNames[] =
static char* static char*
atomToName(nsIAtom* aAtom) atomToName(nsIAtom* aAtom)
{ {
const PRUnichar *namePRU; const char *namePRU;
aAtom->GetUnicode(&namePRU); aAtom->GetUTF8String(&namePRU);
return ToNewUTF8String(nsDependentString(namePRU)); return ToNewCString(nsDependentCString(namePRU));
} }
static PRUint16* gUserDefinedCCMap = nsnull; static PRUint16* gUserDefinedCCMap = nsnull;
@ -1385,9 +1385,9 @@ NS_IMETHODIMP nsFontMetricsGTK::Init(const nsFont& aFont, nsIAtom* aLangGroup,
name.Append("variable"); name.Append("variable");
} }
name.Append(char('.')); name.Append(char('.'));
const PRUnichar* langGroup = nsnull; const char* langGroup = nsnull;
mLangGroup->GetUnicode(&langGroup); mLangGroup->GetUTF8String(&langGroup);
name.AppendWithConversion(langGroup); name.Append(langGroup);
PRInt32 minimum = 0; PRInt32 minimum = 0;
res = gPref->GetIntPref(name.get(), &minimum); res = gPref->GetIntPref(name.get(), &minimum);
if (NS_FAILED(res)) { if (NS_FAILED(res)) {
@ -6102,9 +6102,9 @@ nsFontMetricsGTK::FindLangGroupPrefFont(nsIAtom* aLangGroup, PRUint32 aChar)
// check user set pref // check user set pref
nsCAutoString pref = prefix; nsCAutoString pref = prefix;
pref.Append(char('.')); pref.Append(char('.'));
const PRUnichar* langGroup = nsnull; const char* langGroup = nsnull;
aLangGroup->GetUnicode(&langGroup); aLangGroup->GetUTF8String(&langGroup);
pref.AppendWithConversion(langGroup); pref.Append(langGroup);
nsXPIDLCString value; nsXPIDLCString value;
gPref->CopyCharPref(pref.get(), getter_Copies(value)); gPref->CopyCharPref(pref.get(), getter_Copies(value));
nsCAutoString str; nsCAutoString str;

View File

@ -298,10 +298,10 @@ nsFontMetricsXft::Init(const nsFont& aFont, nsIAtom* aLangGroup,
name.Append(char('.')); name.Append(char('.'));
const PRUnichar* langGroup = nsnull; nsCAutoString name;
mLangGroup->GetUnicode(&langGroup); mLangGroup->GetUTF8String(&langGroup);
name.AppendWithConversion(langGroup); name.Append(langGroup);
PRInt32 minimum = 0; PRInt32 minimum = 0;
nsresult res; nsresult res;
@ -802,10 +802,10 @@ nsFontMetricsXft::SetupFCPattern(void)
} }
// language group // language group
const PRUnichar *name; const char *name;
mLangGroup->GetUnicode(&name); mLangGroup->Get(&name);
nsCAutoString cname; nsCAutoString cname;
cname.AssignWithConversion(nsDependentString(name)); cname.Assign(name);
printf("\tlang group: %s\n", cname.get()); printf("\tlang group: %s\n", cname.get());
@ -1671,10 +1671,8 @@ void
AddLangGroup(FcPattern *aPattern, nsIAtom *aLangGroup) AddLangGroup(FcPattern *aPattern, nsIAtom *aLangGroup)
{ {
// Find the FC lang group for this lang group // Find the FC lang group for this lang group
const PRUnichar *name;
aLangGroup->GetUnicode(&name);
nsCAutoString cname; nsCAutoString cname;
cname.AssignWithConversion(nsDependentString(name)); aLangGroup->ToUTF8String(cname);
// see if the lang group needs to be translated from mozilla's // see if the lang group needs to be translated from mozilla's
// internal mapping into fontconfig's // internal mapping into fontconfig's

View File

@ -599,9 +599,8 @@ nsFontMetricsOS2::SetFontHandle( HPS aPS, nsFontOS2* aFont )
// Encoding: // Encoding:
// There doesn't seem to be any encoding stuff yet, so guess. // There doesn't seem to be any encoding stuff yet, so guess.
// (XXX unicode hack; use same codepage as converter!) // (XXX unicode hack; use same codepage as converter!)
const PRUnichar* langGroup = nsnull; const char* langGroup;
mLangGroup->GetUnicode(&langGroup); mLangGroup->GetUTF8String(&langGroup);
nsCAutoString name(NS_LossyConvertUCS2toASCII(langGroup).get());
for (int j=0; j < eCharset_COUNT; j++ ) for (int j=0; j < eCharset_COUNT; j++ )
{ {
if (name.get()[0] == gCharsetInfo[j].mLangGroup[0]) if (name.get()[0] == gCharsetInfo[j].mLangGroup[0])

View File

@ -163,18 +163,12 @@ NS_IMETHODIMP nsFontMetricsPh::Init ( const nsFont& aFont, nsIAtom* aLangGroup,
str = strdup("serif"); str = strdup("serif");
} }
const PRUnichar *uc; const char *cstring;
aLangGroup->GetUnicode( &uc ); aLangGroup->GetUTF8String( &uc );
nsString language( uc );
char *cstring = ToNewCString(language);
char prop[256]; char prop[256];
sprintf( prop, "font.name.%s.%s", str, cstring ); sprintf( prop, "font.name.%s.%s", str, cstring );
/* Free cstring. */
if (cstring)
free (cstring);
char *font_default = NULL; char *font_default = NULL;
nsIPref* prefs = nsnull; nsIPref* prefs = nsnull;
nsServiceManager::GetService(kPrefCID, NS_GET_IID(nsIPref), (nsISupports**) &prefs); nsServiceManager::GetService(kPrefCID, NS_GET_IID(nsIPref), (nsISupports**) &prefs);

View File

@ -866,13 +866,13 @@ nsFontPSFreeType::FindFont(PRUnichar aChar, const nsFont& aFont,
aFontMetrics->GetLangGroup(getter_AddRefs(lang)); aFontMetrics->GetLangGroup(getter_AddRefs(lang));
if (!lang) if (!lang)
lang = NS_NewAtom("x-western"); lang = NS_NewAtom("x-western");
const PRUnichar *langStr; const char *langStr;
lang->GetUnicode(&langStr); lang->GetUTF8String(&langStr);
if (langStr) if (langStr)
fpi.lang.AppendWithConversion(langStr); fpi.lang.Append(langStr);
gUsersLocale->GetUnicode(&langStr); gUsersLocale->GetUTF8String(&langStr);
if (langStr) if (langStr)
locale.AppendWithConversion(langStr); locale.Append(langStr);
if (NS_IS_BOLD(fpi.nsfont->weight)) if (NS_IS_BOLD(fpi.nsfont->weight))
fpi.weight = nsIFontCatalogService::kFCWeightBold; fpi.weight = nsIFontCatalogService::kFCWeightBold;
else else

View File

@ -2203,7 +2203,7 @@ nsFontMetricsWin::CreateFontAdjustHandle(HDC aDC, LOGFONT* aLogFont)
} }
HFONT HFONT
nsFontMetricsWin::CreateFontHandle(HDC aDC, nsString* aName, LOGFONT* aLogFont) nsFontMetricsWin::CreateFontHandle(HDC aDC, const nsString& aName, LOGFONT* aLogFont)
{ {
PRUint16 weightTable = LookForFontWeightTable(aDC, aName); PRUint16 weightTable = LookForFontWeightTable(aDC, aName);
PRInt32 weight = GetFontWeight(mFont.weight, weightTable); PRInt32 weight = GetFontWeight(mFont.weight, weightTable);
@ -2215,7 +2215,7 @@ nsFontMetricsWin::CreateFontHandle(HDC aDC, nsString* aName, LOGFONT* aLogFont)
* but we don't really have a choice since CreateFontIndirectW is * but we don't really have a choice since CreateFontIndirectW is
* not supported on Windows 9X (see below) -- erik * not supported on Windows 9X (see below) -- erik
*/ */
WideCharToMultiByte(CP_ACP, 0, aName->get(), aName->Length() + 1, WideCharToMultiByte(CP_ACP, 0, aName.get(), aName.Length() + 1,
aLogFont->lfFaceName, sizeof(aLogFont->lfFaceName), nsnull, nsnull); aLogFont->lfFaceName, sizeof(aLogFont->lfFaceName), nsnull, nsnull);
if (mFont.sizeAdjust <= 0) { if (mFont.sizeAdjust <= 0) {
@ -2228,7 +2228,7 @@ nsFontMetricsWin::CreateFontHandle(HDC aDC, nsString* aName, LOGFONT* aLogFont)
HFONT HFONT
nsFontMetricsWin::CreateFontHandle(HDC aDC, nsGlobalFont* aGlobalFont, LOGFONT* aLogFont) nsFontMetricsWin::CreateFontHandle(HDC aDC, nsGlobalFont* aGlobalFont, LOGFONT* aLogFont)
{ {
PRUint16 weightTable = LookForFontWeightTable(aDC, &aGlobalFont->name); PRUint16 weightTable = LookForFontWeightTable(aDC, aGlobalFont->name);
PRInt32 weight = GetFontWeight(mFont.weight, weightTable); PRInt32 weight = GetFontWeight(mFont.weight, weightTable);
FillLogFont(aLogFont, weight); FillLogFont(aLogFont, weight);
@ -2244,7 +2244,7 @@ nsFontMetricsWin::CreateFontHandle(HDC aDC, nsGlobalFont* aGlobalFont, LOGFONT*
} }
nsFontWin* nsFontWin*
nsFontMetricsWin::LoadFont(HDC aDC, nsString* aName) nsFontMetricsWin::LoadFont(HDC aDC, const nsString& aName)
{ {
LOGFONT logFont; LOGFONT logFont;
HFONT hfont = CreateFontHandle(aDC, aName, &logFont); HFONT hfont = CreateFontHandle(aDC, aName, &logFont);
@ -2559,7 +2559,7 @@ nsFontMetricsWin::FindSubstituteFont(HDC aDC, PRUint32 c)
// that the substitute font also has glyphs for '&', '#', 'x', ';' and digits? // that the substitute font also has glyphs for '&', '#', 'x', ';' and digits?
// (Because this is a unicode font, those glyphs should in principle be there.) // (Because this is a unicode font, those glyphs should in principle be there.)
name.AssignWithConversion(font->mName); name.AssignWithConversion(font->mName);
font = LoadSubstituteFont(aDC, &name); font = LoadSubstituteFont(aDC, name);
if (font) { if (font) {
((nsFontWinSubstitute*)font)->SetRepresentable(c); ((nsFontWinSubstitute*)font)->SetRepresentable(c);
mSubstituteFont = font; mSubstituteFont = font;
@ -2580,7 +2580,7 @@ nsFontMetricsWin::FindSubstituteFont(HDC aDC, PRUint32 c)
continue; continue;
} }
if (CCMAP_HAS_CHAR(globalFont->ccmap, NS_REPLACEMENT_CHAR)) { if (CCMAP_HAS_CHAR(globalFont->ccmap, NS_REPLACEMENT_CHAR)) {
nsFontWin* font = LoadSubstituteFont(aDC, &globalFont->name); nsFontWin* font = LoadSubstituteFont(aDC, globalFont->name);
if (font) { if (font) {
((nsFontWinSubstitute*)font)->SetRepresentable(c); ((nsFontWinSubstitute*)font)->SetRepresentable(c);
mSubstituteFont = font; mSubstituteFont = font;
@ -2591,7 +2591,7 @@ nsFontMetricsWin::FindSubstituteFont(HDC aDC, PRUint32 c)
// We are running out of resources if we reach here... Try a stock font // We are running out of resources if we reach here... Try a stock font
NS_ASSERTION(::GetMapMode(aDC) == MM_TEXT, "mapping mode needs to be MM_TEXT"); NS_ASSERTION(::GetMapMode(aDC) == MM_TEXT, "mapping mode needs to be MM_TEXT");
nsFontWin* font = LoadSubstituteFont(aDC, nsnull); nsFontWin* font = LoadSubstituteFont(aDC, nsString());
if (font) { if (font) {
((nsFontWinSubstitute*)font)->SetRepresentable(c); ((nsFontWinSubstitute*)font)->SetRepresentable(c);
mSubstituteFont = font; mSubstituteFont = font;
@ -2603,17 +2603,17 @@ nsFontMetricsWin::FindSubstituteFont(HDC aDC, PRUint32 c)
} }
nsFontWin* nsFontWin*
nsFontMetricsWin::LoadSubstituteFont(HDC aDC, nsString* aName) nsFontMetricsWin::LoadSubstituteFont(HDC aDC, const nsString& aName)
{ {
LOGFONT logFont; LOGFONT logFont;
HFONT hfont = aName HFONT hfont = !aName.IsEmpty()
? CreateFontHandle(aDC, aName, &logFont) ? CreateFontHandle(aDC, aName, &logFont)
: (HFONT)::GetStockObject(SYSTEM_FONT); : (HFONT)::GetStockObject(SYSTEM_FONT);
if (hfont) { if (hfont) {
// XXX 'displayUnicode' has to be initialized based on the desired rendering mode // XXX 'displayUnicode' has to be initialized based on the desired rendering mode
PRBool displayUnicode = PR_FALSE; PRBool displayUnicode = PR_FALSE;
/* substitute font does not need ccmap */ /* substitute font does not need ccmap */
LOGFONT* lfont = aName ? &logFont : nsnull; LOGFONT* lfont = !aName.IsEmpty() ? &logFont : nsnull;
nsFontWinSubstitute* font = new nsFontWinSubstitute(lfont, hfont, nsnull, displayUnicode); nsFontWinSubstitute* font = new nsFontWinSubstitute(lfont, hfont, nsnull, displayUnicode);
if (font) { if (font) {
HFONT oldFont = (HFONT)::SelectObject(aDC, (HGDIOBJ)hfont); HFONT oldFont = (HFONT)::SelectObject(aDC, (HGDIOBJ)hfont);
@ -2782,12 +2782,12 @@ SearchSimulatedFontWeight(HDC aDC, nsFontWeightInfo* aWeightInfo)
} }
PRUint16 PRUint16
nsFontMetricsWin::GetFontWeightTable(HDC aDC, nsString* aFontName) nsFontMetricsWin::GetFontWeightTable(HDC aDC, const nsString& aFontName)
{ {
// Look for all of the weights for a given font. // Look for all of the weights for a given font.
LOGFONT logFont; LOGFONT logFont;
logFont.lfCharSet = DEFAULT_CHARSET; logFont.lfCharSet = DEFAULT_CHARSET;
WideCharToMultiByte(CP_ACP, 0, aFontName->get(), aFontName->Length() + 1, WideCharToMultiByte(CP_ACP, 0, aFontName.get(), aFontName.Length() + 1,
logFont.lfFaceName, sizeof(logFont.lfFaceName), nsnull, nsnull); logFont.lfFaceName, sizeof(logFont.lfFaceName), nsnull, nsnull);
logFont.lfPitchAndFamily = 0; logFont.lfPitchAndFamily = 0;
@ -2936,7 +2936,7 @@ nsFontMetricsWin::GetFontWeight(PRInt32 aWeight, PRUint16 aWeightTable)
} }
PRUint16 PRUint16
nsFontMetricsWin::LookForFontWeightTable(HDC aDC, nsString* aName) nsFontMetricsWin::LookForFontWeightTable(HDC aDC, const nsString& aName)
{ {
// Initialize the font weight table if need be. // Initialize the font weight table if need be.
if (!gFontWeights) { if (!gFontWeights) {
@ -2950,7 +2950,7 @@ nsFontMetricsWin::LookForFontWeightTable(HDC aDC, nsString* aName)
// Use lower case name for hash table searches. This eliminates // Use lower case name for hash table searches. This eliminates
// keeping multiple font weights entries when the font name varies // keeping multiple font weights entries when the font name varies
// only by case. // only by case.
nsAutoString low(*aName); nsAutoString low(aName);
ToLowerCase(low); ToLowerCase(low);
// See if the font weight has already been computed. // See if the font weight has already been computed.
@ -2994,7 +2994,7 @@ nsFontMetricsWin::FindUserDefinedFont(HDC aDC, PRUint32 aChar)
{ {
if (mIsUserDefined) { if (mIsUserDefined) {
// the user-defined font is always loaded as the first font // the user-defined font is always loaded as the first font
nsFontWin* font = LoadFont(aDC, &mUserDefined); nsFontWin* font = LoadFont(aDC, mUserDefined);
mIsUserDefined = PR_FALSE; mIsUserDefined = PR_FALSE;
if (font && font->HasGlyph(aChar)) if (font && font->HasGlyph(aChar))
return font; return font;
@ -3110,7 +3110,7 @@ nsFontMetricsWin::FindLocalFont(HDC aDC, PRUint32 aChar)
if (!winName) { if (!winName) {
winName = name; winName = name;
} }
nsFontWin* font = LoadFont(aDC, winName); nsFontWin* font = LoadFont(aDC, *winName);
if (font && font->HasGlyph(aChar)) { if (font && font->HasGlyph(aChar)) {
return font; return font;
} }
@ -3119,14 +3119,14 @@ nsFontMetricsWin::FindLocalFont(HDC aDC, PRUint32 aChar)
} }
nsFontWin* nsFontWin*
nsFontMetricsWin::LoadGenericFont(HDC aDC, PRUint32 aChar, nsString* aName) nsFontMetricsWin::LoadGenericFont(HDC aDC, PRUint32 aChar, const nsString& aName)
{ {
for (int i = mLoadedFonts.Count()-1; i >= 0; --i) { for (int i = mLoadedFonts.Count()-1; i >= 0; --i) {
// woah, this seems bad // woah, this seems bad
const nsACString& fontName = const nsACString& fontName =
nsDependentCString(((nsFontWin*)mLoadedFonts[i])->mName); nsDependentCString(((nsFontWin*)mLoadedFonts[i])->mName);
if (aName->Equals(NS_ConvertASCIItoUCS2(((nsFontWin*)mLoadedFonts[i])->mName), if (aName.Equals(NS_ConvertASCIItoUCS2(fontName),
nsCaseInsensitiveStringComparator())) nsCaseInsensitiveStringComparator()))
return nsnull; return nsnull;
} }
@ -3152,7 +3152,7 @@ GenericFontEnumCallback(const nsString& aFamily, PRBool aGeneric, void* aData)
HDC dc = context->mDC; HDC dc = context->mDC;
PRUint32 ch = context->mChar; PRUint32 ch = context->mChar;
nsFontMetricsWin* metrics = context->mMetrics; nsFontMetricsWin* metrics = context->mMetrics;
context->mFont = metrics->LoadGenericFont(dc, ch, (nsString*)&aFamily); context->mFont = metrics->LoadGenericFont(dc, ch, aFamily);
if (context->mFont) { if (context->mFont) {
return PR_FALSE; // stop enumerating the list return PR_FALSE; // stop enumerating the list
} }
@ -3211,10 +3211,9 @@ nsFontMetricsWin::FindGenericFont(HDC aDC, PRUint32 aChar)
nsFont font("", 0, 0, 0, 0, 0); nsFont font("", 0, 0, 0, 0, 0);
if (mLangGroup) { if (mLangGroup) {
nsAutoString langGroup; const char* langGroup;
mLangGroup->ToString(langGroup); mLangGroup->GetUTF8String(&langGroup);
AppendGenericFontFromPref(font.name, AppendGenericFontFromPref(font.name, langGroup,
NS_ConvertUCS2toUTF8(langGroup).get(),
NS_ConvertUCS2toUTF8(mGeneric).get()); NS_ConvertUCS2toUTF8(mGeneric).get());
} }
@ -3226,13 +3225,12 @@ nsFontMetricsWin::FindGenericFont(HDC aDC, PRUint32 aChar)
} }
#if defined(DEBUG_rbs) || defined(DEBUG_shanjian) #if defined(DEBUG_rbs) || defined(DEBUG_shanjian)
nsAutoString langGroupName; const char* lang;
mLangGroup->ToString(langGroupName); mLangGroup->GetUTF8String(&lang);
nsCAutoString lang; lang.Assign(NS_ConvertUCS2toUTF8(langGroupName)); NS_ConvertUCS2toUTF8 generic(mGeneric);
nsCAutoString generic; generic.Assign(NS_ConvertUCS2toUTF8(mGeneric)); NS_ConvertUCS2toUTF8 family(mFont.name);
nsCAutoString family; family.Assign(NS_ConvertUCS2toUTF8(mFont.name));
printf("FindGenericFont missed:U+%04X langGroup:%s generic:%s mFont.name:%s\n", printf("FindGenericFont missed:U+%04X langGroup:%s generic:%s mFont.name:%s\n",
aChar, lang.get(), generic.get(), family.get()); aChar, lang, generic.get(), family.get());
#endif #endif
mTriedAllGenerics = 1; mTriedAllGenerics = 1;
@ -3279,17 +3277,17 @@ nsFontMetricsWin::FindPrefFont(HDC aDC, PRUint32 aChar)
// then try user locale first, if it is CJK // then try user locale first, if it is CJK
if ((gUsersLocale != mLangGroup) && IsCJKLangGroupAtom(gUsersLocale)) { if ((gUsersLocale != mLangGroup) && IsCJKLangGroupAtom(gUsersLocale)) {
const PRUnichar *usersLocaleLangGroup; nsCAutoString usersLocaleLangGroup;
gUsersLocale->GetUnicode(&usersLocaleLangGroup); gUsersLocale->ToUTF8String(usersLocaleLangGroup);
AppendGenericFontFromPref(font.name, NS_ConvertUCS2toUTF8(usersLocaleLangGroup).get(), AppendGenericFontFromPref(font.name, usersLocaleLangGroup.get(),
NS_ConvertUCS2toUTF8(mGeneric).get()); NS_ConvertUCS2toUTF8(mGeneric).get());
} }
// then system locale (os language) // then system locale (os language)
if ((gSystemLocale != mLangGroup) && (gSystemLocale != gUsersLocale) && IsCJKLangGroupAtom(gSystemLocale)) { if ((gSystemLocale != mLangGroup) && (gSystemLocale != gUsersLocale) && IsCJKLangGroupAtom(gSystemLocale)) {
const PRUnichar *systemLocaleLangGroup; nsCAutoString systemLocaleLangGroup;
gSystemLocale->GetUnicode(&systemLocaleLangGroup); gSystemLocale->ToUTF8String(systemLocaleLangGroup);
AppendGenericFontFromPref(font.name, NS_ConvertUCS2toUTF8(systemLocaleLangGroup).get(), AppendGenericFontFromPref(font.name, systemLocaleLangGroup.get(),
NS_ConvertUCS2toUTF8(mGeneric).get()); NS_ConvertUCS2toUTF8(mGeneric).get());
} }
@ -4601,7 +4599,7 @@ nsFontWinA::DumpFontInfo()
#endif #endif
nsFontWin* nsFontWin*
nsFontMetricsWinA::LoadFont(HDC aDC, nsString* aName) nsFontMetricsWinA::LoadFont(HDC aDC, const nsString& aName)
{ {
LOGFONT logFont; LOGFONT logFont;
HFONT hfont = CreateFontHandle(aDC, aName, &logFont); HFONT hfont = CreateFontHandle(aDC, aName, &logFont);
@ -4734,7 +4732,7 @@ nsFontMetricsWinA::FindLocalFont(HDC aDC, PRUint32 aChar)
if (!winName) { if (!winName) {
winName = name; winName = name;
} }
nsFontWinA* font = (nsFontWinA*)LoadFont(aDC, winName); nsFontWinA* font = (nsFontWinA*)LoadFont(aDC, *winName);
if (font && font->HasGlyph(aChar)) { if (font && font->HasGlyph(aChar)) {
nsFontSubset* subset = font->FindSubset(aDC, (PRUnichar)aChar, this); nsFontSubset* subset = font->FindSubset(aDC, (PRUnichar)aChar, this);
if (subset) if (subset)
@ -4746,12 +4744,11 @@ nsFontMetricsWinA::FindLocalFont(HDC aDC, PRUint32 aChar)
} }
nsFontWin* nsFontWin*
nsFontMetricsWinA::LoadGenericFont(HDC aDC, PRUint32 aChar, nsString* aName) nsFontMetricsWinA::LoadGenericFont(HDC aDC, PRUint32 aChar, const nsString& aName)
{ {
for (int i = mLoadedFonts.Count()-1; i >= 0; --i) { for (int i = mLoadedFonts.Count()-1; i >= 0; --i) {
if (aName->Equals(NS_ConvertASCIItoUCS2(((nsFontWin*)mLoadedFonts[i])->mName), if (aName.EqualsIgnoreCase(((nsFontWin*)mLoadedFonts[i])->mName))
nsCaseInsensitiveStringComparator()))
return nsnull; return nsnull;
} }
@ -4877,7 +4874,7 @@ nsFontMetricsWinA::FindSubstituteFont(HDC aDC, PRUint32 aChar)
// make a substitute font from this one // make a substitute font from this one
nsAutoString name; nsAutoString name;
name.AssignWithConversion(font->mName); name.AssignWithConversion(font->mName);
nsFontWinSubstituteA* substituteFont = (nsFontWinSubstituteA*)LoadSubstituteFont(aDC, &name); nsFontWinSubstituteA* substituteFont = (nsFontWinSubstituteA*)LoadSubstituteFont(aDC, name);
if (substituteFont) { if (substituteFont) {
nsFontSubset* substituteSubset = substituteFont->mSubsets[0]; nsFontSubset* substituteSubset = substituteFont->mSubsets[0];
substituteSubset->mCharset = subset->mCharset; substituteSubset->mCharset = subset->mCharset;
@ -4919,7 +4916,7 @@ nsFontMetricsWinA::FindSubstituteFont(HDC aDC, PRUint32 aChar)
delete font; delete font;
if (charset != DEFAULT_CHARSET) { if (charset != DEFAULT_CHARSET) {
// make a substitute font now // make a substitute font now
nsFontWinSubstituteA* substituteFont = (nsFontWinSubstituteA*)LoadSubstituteFont(aDC, &globalFont->name); nsFontWinSubstituteA* substituteFont = (nsFontWinSubstituteA*)LoadSubstituteFont(aDC, globalFont->name);
if (substituteFont) { if (substituteFont) {
nsFontSubset* substituteSubset = substituteFont->mSubsets[0]; nsFontSubset* substituteSubset = substituteFont->mSubsets[0];
substituteSubset->mCharset = charset; substituteSubset->mCharset = charset;
@ -4941,7 +4938,7 @@ nsFontMetricsWinA::FindSubstituteFont(HDC aDC, PRUint32 aChar)
} }
nsFontWin* nsFontWin*
nsFontMetricsWinA::LoadSubstituteFont(HDC aDC, nsString* aName) nsFontMetricsWinA::LoadSubstituteFont(HDC aDC, const nsString& aName)
{ {
LOGFONT logFont; LOGFONT logFont;
HFONT hfont = CreateFontHandle(aDC, aName, &logFont); HFONT hfont = CreateFontHandle(aDC, aName, &logFont);

View File

@ -227,10 +227,10 @@ public:
virtual nsFontWin* FindGlobalFont(HDC aDC, PRUint32 aChar); virtual nsFontWin* FindGlobalFont(HDC aDC, PRUint32 aChar);
virtual nsFontWin* FindSubstituteFont(HDC aDC, PRUint32 aChar); virtual nsFontWin* FindSubstituteFont(HDC aDC, PRUint32 aChar);
virtual nsFontWin* LoadFont(HDC aDC, nsString* aName); virtual nsFontWin* LoadFont(HDC aDC, const nsString& aName);
virtual nsFontWin* LoadGenericFont(HDC aDC, PRUint32 aChar, nsString* aName); virtual nsFontWin* LoadGenericFont(HDC aDC, PRUint32 aChar, const nsString& aName);
virtual nsFontWin* LoadGlobalFont(HDC aDC, nsGlobalFont* aGlobalFontItem); virtual nsFontWin* LoadGlobalFont(HDC aDC, nsGlobalFont* aGlobalFontItem);
virtual nsFontWin* LoadSubstituteFont(HDC aDC, nsString* aName); virtual nsFontWin* LoadSubstituteFont(HDC aDC, const nsString& aName);
virtual nsFontWin* GetFontFor(HFONT aHFONT); virtual nsFontWin* GetFontFor(HFONT aHFONT);
@ -266,7 +266,7 @@ public:
static int SameAsPreviousMap(int aIndex); static int SameAsPreviousMap(int aIndex);
// These functions create possibly adjusted fonts // These functions create possibly adjusted fonts
HFONT CreateFontHandle(HDC aDC, nsString* aName, LOGFONT* aLogFont); HFONT CreateFontHandle(HDC aDC, const nsString& aName, LOGFONT* aLogFont);
HFONT CreateFontHandle(HDC aDC, nsGlobalFont* aGlobalFont, LOGFONT* aLogFont); HFONT CreateFontHandle(HDC aDC, nsGlobalFont* aGlobalFont, LOGFONT* aLogFont);
HFONT CreateFontAdjustHandle(HDC aDC, LOGFONT* aLogFont); HFONT CreateFontAdjustHandle(HDC aDC, LOGFONT* aLogFont);
void InitMetricsFor(HDC aDC, nsFontWin* aFontWin); void InitMetricsFor(HDC aDC, nsFontWin* aFontWin);
@ -287,12 +287,12 @@ protected:
// what font weight to pass in the LOGFONT structure. // what font weight to pass in the LOGFONT structure.
// Utility methods for managing font weights. // Utility methods for managing font weights.
PRUint16 LookForFontWeightTable(HDC aDc, nsString* aName); PRUint16 LookForFontWeightTable(HDC aDc, const nsString& aName);
PRInt32 GetBolderWeight(PRInt32 aWeight, PRInt32 aDistance, PRUint16 aWeightTable); PRInt32 GetBolderWeight(PRInt32 aWeight, PRInt32 aDistance, PRUint16 aWeightTable);
PRInt32 GetLighterWeight(PRInt32 aWeight, PRInt32 aDistance, PRUint16 aWeightTable); PRInt32 GetLighterWeight(PRInt32 aWeight, PRInt32 aDistance, PRUint16 aWeightTable);
PRInt32 GetFontWeight(PRInt32 aWeight, PRUint16 aWeightTable); PRInt32 GetFontWeight(PRInt32 aWeight, PRUint16 aWeightTable);
PRInt32 GetClosestWeight(PRInt32 aWeight, PRUint16 aWeightTable); PRInt32 GetClosestWeight(PRInt32 aWeight, PRUint16 aWeightTable);
PRUint16 GetFontWeightTable(HDC aDC, nsString* aFontName); PRUint16 GetFontWeightTable(HDC aDC, const nsString& aFontName);
nsFontWin* LocateFont(HDC aDC, PRUint32 aChar, PRInt32 & aCount); nsFontWin* LocateFont(HDC aDC, PRUint32 aChar, PRInt32 & aCount);
nsresult RealizeFont(); nsresult RealizeFont();
@ -388,13 +388,13 @@ class nsFontMetricsWinA : public nsFontMetricsWin
{ {
public: public:
virtual nsFontWin* FindLocalFont(HDC aDC, PRUint32 aChar); virtual nsFontWin* FindLocalFont(HDC aDC, PRUint32 aChar);
virtual nsFontWin* LoadGenericFont(HDC aDC, PRUint32 aChar, nsString* aName); virtual nsFontWin* LoadGenericFont(HDC aDC, PRUint32 aChar, const nsString& aName);
virtual nsFontWin* FindGlobalFont(HDC aDC, PRUint32 aChar); virtual nsFontWin* FindGlobalFont(HDC aDC, PRUint32 aChar);
virtual nsFontWin* FindSubstituteFont(HDC aDC, PRUint32 aChar); virtual nsFontWin* FindSubstituteFont(HDC aDC, PRUint32 aChar);
virtual nsFontWin* LoadFont(HDC aDC, nsString* aName); virtual nsFontWin* LoadFont(HDC aDC, const nsString& aName);
virtual nsFontWin* LoadGlobalFont(HDC aDC, nsGlobalFont* aGlobalFontItem); virtual nsFontWin* LoadGlobalFont(HDC aDC, nsGlobalFont* aGlobalFontItem);
virtual nsFontWin* LoadSubstituteFont(HDC aDC, nsString* aName); virtual nsFontWin* LoadSubstituteFont(HDC aDC, const nsString& aName);
virtual nsFontWin* GetFontFor(HFONT aHFONT); virtual nsFontWin* GetFontFor(HFONT aHFONT);

View File

@ -853,9 +853,9 @@ PRBool CopyFontCharSetMapXlib(nsFontMetricsXlibContext *aFmctx)
static char* static char*
atomToName(nsIAtom* aAtom) atomToName(nsIAtom* aAtom)
{ {
const PRUnichar *namePRU; const char *namePRU;
aAtom->GetUnicode(&namePRU); aAtom->GetUTF8String(&namePRU);
return ToNewUTF8String(nsDependentString(namePRU)); return ToNewCString(nsDependentCString(namePRU));
} }
// //
@ -1740,9 +1740,9 @@ NS_IMETHODIMP nsFontMetricsXlib::Init(const nsFont& aFont, nsIAtom* aLangGroup,
name.Append("variable"); name.Append("variable");
} }
name.Append(char('.')); name.Append(char('.'));
const PRUnichar* langGroup = nsnull; const char* langGroup = nsnull;
mLangGroup->GetUnicode(&langGroup); mLangGroup->GetUTF8String(&langGroup);
name.AppendWithConversion(langGroup); name.Append(langGroup);
PRInt32 minimum = 0; PRInt32 minimum = 0;
res = mFontMetricsContext->mPref->GetIntPref(name.get(), &minimum); res = mFontMetricsContext->mPref->GetIntPref(name.get(), &minimum);
if (NS_FAILED(res)) { if (NS_FAILED(res)) {
@ -5427,9 +5427,9 @@ nsFontMetricsXlib::FindLangGroupPrefFont(nsIAtom* aLangGroup, PRUnichar aChar)
// check user set pref // check user set pref
nsCAutoString pref = prefix; nsCAutoString pref = prefix;
pref.Append(char('.')); pref.Append(char('.'));
const PRUnichar* langGroup = nsnull; const char* langGroup = nsnull;
aLangGroup->GetUnicode(&langGroup); aLangGroup->GetUTF8String(&langGroup);
pref.AppendWithConversion(langGroup); pref.Append(langGroup);
nsXPIDLCString value; nsXPIDLCString value;
mFontMetricsContext->mPref->CopyCharPref(pref.get(), getter_Copies(value)); mFontMetricsContext->mPref->CopyCharPref(pref.get(), getter_Copies(value));
nsCAutoString str; nsCAutoString str;

View File

@ -44,11 +44,10 @@ NS_IMPL_ISUPPORTS1(nsParserService, nsIParserService)
NS_IMETHODIMP NS_IMETHODIMP
nsParserService::HTMLAtomTagToId(nsIAtom* aAtom, PRInt32* aId) const nsParserService::HTMLAtomTagToId(nsIAtom* aAtom, PRInt32* aId) const
{ {
const PRUnichar *tagName = nsnull; nsAutoString tagName;
aAtom->GetUnicode(&tagName); aAtom->ToString(tagName);
NS_ASSERTION(tagName, "Null string in atom!");
*aId = nsHTMLTags::LookupTag(nsDependentString(tagName)); *aId = nsHTMLTags::LookupTag(tagName);
return NS_OK; return NS_OK;
} }
@ -57,11 +56,10 @@ NS_IMETHODIMP
nsParserService::HTMLCaseSensitiveAtomTagToId(nsIAtom* aAtom, nsParserService::HTMLCaseSensitiveAtomTagToId(nsIAtom* aAtom,
PRInt32* aId) const PRInt32* aId) const
{ {
const PRUnichar *tagName = nsnull; nsAutoString tagName;
aAtom->GetUnicode(&tagName); aAtom->ToString(tagName);
NS_ASSERTION(tagName, "Null string in atom!");
*aId = nsHTMLTags::CaseSensitiveLookupTag(tagName); *aId = nsHTMLTags::CaseSensitiveLookupTag(tagName.get());
return NS_OK; return NS_OK;
} }

View File

@ -382,10 +382,10 @@ nsPlatformCharset::VerifyCharset(nsString &aCharset)
// //
// return the preferred string // return the preferred string
// //
const PRUnichar *prefName; const char *prefName;
res = charsetAtom->GetUnicode(&prefName); res = charsetAtom->GetUTF8String(&prefName);
if (NS_SUCCEEDED(res)) if (NS_SUCCEEDED(res))
aCharset.Assign(prefName); aCharset.AssignWithConversion(prefName);
NS_ASSERTION(NS_SUCCEEDED(res), "failed to get preferred charset name, using non-preferred"); NS_ASSERTION(NS_SUCCEEDED(res), "failed to get preferred charset name, using non-preferred");
return NS_OK; return NS_OK;
} }

View File

@ -245,7 +245,7 @@ nsresult nsTestUConv::TestCharsetManager()
char * trace = "TestCharsetManager"; char * trace = "TestCharsetManager";
mLog.AddTrace(trace); mLog.AddTrace(trace);
nsresult res = NS_OK; nsresult res = NS_OK;
const PRUnichar * name; nsAutoString name;
nsCOMPtr<nsIAtom> csAtom; nsCOMPtr<nsIAtom> csAtom;
nsCOMPtr<nsICharsetConverterManager2> ccMan = nsCOMPtr<nsICharsetConverterManager2> ccMan =
@ -263,12 +263,12 @@ nsresult nsTestUConv::TestCharsetManager()
mLog.PrintError("GetCharsetAtom()", res); mLog.PrintError("GetCharsetAtom()", res);
return res; return res;
} }
res = csAtom->GetUnicode(&name); res = csAtom->ToString(name);
if (NS_FAILED(res)) { if (NS_FAILED(res)) {
mLog.PrintError("get()", res); mLog.PrintError("get()", res);
return res; return res;
} }
if (!csName.Equals(nsDependentString(name))) { if (!csName.Equals(name)) {
mLog.PrintError("Equals()", "unexpected charset name"); mLog.PrintError("Equals()", "unexpected charset name");
return NS_ERROR_UNEXPECTED; return NS_ERROR_UNEXPECTED;
} }
@ -280,12 +280,12 @@ nsresult nsTestUConv::TestCharsetManager()
mLog.PrintError("GetCharsetAtom()", res); mLog.PrintError("GetCharsetAtom()", res);
return res; return res;
} }
res = csAtom->GetUnicode(&name); res = csAtom->ToString(name);
if (NS_FAILED(res)) { if (NS_FAILED(res)) {
mLog.PrintError("get()", res); mLog.PrintError("get()", res);
return res; return res;
} }
if (!csAlias2.Equals(nsDependentString(name))) { if (!csAlias2.Equals(name)) {
mLog.PrintError("Equals()", "unexpected charset name"); mLog.PrintError("Equals()", "unexpected charset name");
return NS_ERROR_UNEXPECTED; return NS_ERROR_UNEXPECTED;
} }
@ -335,8 +335,8 @@ nsresult nsTestUConv::DisplayDetectors()
return res; return res;
} }
const PRUnichar * name; nsAutoString name;
res = cs->GetUnicode(&name); res = cs->ToString(name);
if (NS_FAILED(res)) { if (NS_FAILED(res)) {
mLog.PrintError("get()", res); mLog.PrintError("get()", res);
return res; return res;
@ -410,8 +410,8 @@ nsresult nsTestUConv::DisplayCharsets()
return res; return res;
} }
const PRUnichar * name; nsAutoString name;
res = cs->GetUnicode(&name); res = cs->ToString(name);
if (NS_FAILED(res)) { if (NS_FAILED(res)) {
mLog.PrintError("get()", res); mLog.PrintError("get()", res);
return res; return res;

View File

@ -2250,6 +2250,16 @@ static inline void KeyAppendString(const nsAString& aString, nsACString& aKey)
aKey.Append(NS_ConvertUCS2toUTF8(aString)); aKey.Append(NS_ConvertUCS2toUTF8(aString));
} }
static inline void KeyAppendString(const nsACString& aString, nsACString& aKey)
{
KeyAppendSep(aKey);
// Could escape separator here if collisions happen. > is not a legal char
// for a name or type attribute, so we should be safe avoiding that extra work.
aKey.Append(aString);
}
static inline void KeyAppendInt(PRInt32 aInt, nsACString& aKey) static inline void KeyAppendInt(PRInt32 aInt, nsACString& aKey)
{ {
KeyAppendSep(aKey); KeyAppendSep(aKey);
@ -2261,10 +2271,10 @@ static inline void KeyAppendAtom(nsIAtom* aAtom, nsACString& aKey)
{ {
NS_PRECONDITION(aAtom, "KeyAppendAtom: aAtom can not be null!\n"); NS_PRECONDITION(aAtom, "KeyAppendAtom: aAtom can not be null!\n");
const PRUnichar* atomString = nsnull; const char* atomString = nsnull;
aAtom->GetUnicode(&atomString); aAtom->GetUTF8String(&atomString);
KeyAppendString(nsDependentString(atomString), aKey); KeyAppendString(nsDependentCString(atomString), aKey);
} }
static inline PRBool IsAutocompleteOff(nsIDOMElement* aElement) static inline PRBool IsAutocompleteOff(nsIDOMElement* aElement)

View File

@ -2250,6 +2250,16 @@ static inline void KeyAppendString(const nsAString& aString, nsACString& aKey)
aKey.Append(NS_ConvertUCS2toUTF8(aString)); aKey.Append(NS_ConvertUCS2toUTF8(aString));
} }
static inline void KeyAppendString(const nsACString& aString, nsACString& aKey)
{
KeyAppendSep(aKey);
// Could escape separator here if collisions happen. > is not a legal char
// for a name or type attribute, so we should be safe avoiding that extra work.
aKey.Append(aString);
}
static inline void KeyAppendInt(PRInt32 aInt, nsACString& aKey) static inline void KeyAppendInt(PRInt32 aInt, nsACString& aKey)
{ {
KeyAppendSep(aKey); KeyAppendSep(aKey);
@ -2261,10 +2271,10 @@ static inline void KeyAppendAtom(nsIAtom* aAtom, nsACString& aKey)
{ {
NS_PRECONDITION(aAtom, "KeyAppendAtom: aAtom can not be null!\n"); NS_PRECONDITION(aAtom, "KeyAppendAtom: aAtom can not be null!\n");
const PRUnichar* atomString = nsnull; const char* atomString = nsnull;
aAtom->GetUnicode(&atomString); aAtom->GetUTF8String(&atomString);
KeyAppendString(nsDependentString(atomString), aKey); KeyAppendString(nsDependentCString(atomString), aKey);
} }
static inline PRBool IsAutocompleteOff(nsIDOMElement* aElement) static inline PRBool IsAutocompleteOff(nsIDOMElement* aElement)

View File

@ -615,9 +615,6 @@ nsMathMLFrame::MapAttributesIntoCSS(nsIPresContext* aPresContext,
if (attrValue.IsEmpty()) if (attrValue.IsEmpty())
continue; continue;
const PRUnichar* attrName;
attrAtom->GetUnicode(&attrName);
// don't add rules that are already in mathml.css // don't add rules that are already in mathml.css
// (this will also clean up whitespace before units - see bug 125303) // (this will also clean up whitespace before units - see bug 125303)
if (attrAtom == nsMathMLAtoms::fontsize_ || attrAtom == nsMathMLAtoms::mathsize_) { if (attrAtom == nsMathMLAtoms::fontsize_ || attrAtom == nsMathMLAtoms::mathsize_) {
@ -632,9 +629,12 @@ nsMathMLFrame::MapAttributesIntoCSS(nsIPresContext* aPresContext,
else else
cssProperty.Append(attrValue); cssProperty.Append(attrValue);
nsAutoString attrName;
attrAtom->ToString(attrName);
// make a style rule that maps to the equivalent CSS property // make a style rule that maps to the equivalent CSS property
nsAutoString cssRule; nsAutoString cssRule;
cssRule.Assign(NS_LITERAL_STRING("[") + nsDependentString(attrName) + cssRule.Assign(NS_LITERAL_STRING("[") + attrName +
NS_LITERAL_STRING("='") + attrValue + NS_LITERAL_STRING("='") + attrValue +
NS_LITERAL_STRING("']{") + cssProperty + NS_LITERAL_STRING("}")); NS_LITERAL_STRING("']{") + cssProperty + NS_LITERAL_STRING("}"));
@ -662,7 +662,7 @@ nsMathMLFrame::MapAttributesIntoCSS(nsIPresContext* aPresContext,
// XXX bug 142648 - GetSourceSelectorText is in the format *[color=blue] (i.e., no quotes...) // XXX bug 142648 - GetSourceSelectorText is in the format *[color=blue] (i.e., no quotes...)
// XXXrbs need to keep this in sync with the fix for bug 142648 // XXXrbs need to keep this in sync with the fix for bug 142648
nsAutoString selector; nsAutoString selector;
selector.Assign(NS_LITERAL_STRING("*[") + nsDependentString(attrName) + selector.Assign(NS_LITERAL_STRING("*[") + attrName +
NS_LITERAL_STRING("=") + attrValue + NS_LITERAL_STRING("=") + attrValue +
NS_LITERAL_STRING("]")); NS_LITERAL_STRING("]"));
PRInt32 k, count; PRInt32 k, count;

View File

@ -1569,9 +1569,10 @@ static PRBool IsTreePseudoElement(const nsString& aPseudo)
static PRBool IsTreePseudoElement(nsIAtom* aPseudo) static PRBool IsTreePseudoElement(nsIAtom* aPseudo)
{ {
nsAutoString str; const char* str;
aPseudo->ToString(str); aPseudo->GetUTF8String(&str);
return Substring(str, 0, 11).Equals(NS_LITERAL_STRING(":-moz-tree-")); static const char moz_tree[] = ":-moz-tree-";
return nsCRT::strncmp(str, moz_tree, PRInt32(sizeof(moz_tree)-1)) == 0;
} }
#endif #endif

View File

@ -584,8 +584,8 @@ PRInt32 nsCSSSelector::CalcWeight(void) const
static PRBool IsPseudoElement(nsIAtom* aAtom) static PRBool IsPseudoElement(nsIAtom* aAtom)
{ {
if (aAtom) { if (aAtom) {
const PRUnichar *str; const char* str;
aAtom->GetUnicode(&str); aAtom->GetUTF8String(&str);
return str && (*str == ':'); return str && (*str == ':');
} }
@ -604,7 +604,7 @@ void nsCSSSelector::AppendNegationToString(nsAString& aString)
nsresult nsCSSSelector::ToString( nsAString& aString, nsICSSStyleSheet* aSheet, PRBool aIsPseudoElem, nsresult nsCSSSelector::ToString( nsAString& aString, nsICSSStyleSheet* aSheet, PRBool aIsPseudoElem,
PRInt8 aNegatedIndex) const PRInt8 aNegatedIndex) const
{ {
const PRUnichar* temp; nsAutoString temp;
PRBool aIsNegated = PRBool(0 < aNegatedIndex); PRBool aIsNegated = PRBool(0 < aNegatedIndex);
// selectors are linked from right-to-left, so the next selector in the linked list // selectors are linked from right-to-left, so the next selector in the linked list
@ -631,8 +631,8 @@ nsresult nsCSSSelector::ToString( nsAString& aString, nsICSSStyleSheet* aSheet,
// will return null if namespace was the default // will return null if namespace was the default
sheetNS->FindNameSpacePrefix(mNameSpace, *getter_AddRefs(prefixAtom)); sheetNS->FindNameSpacePrefix(mNameSpace, *getter_AddRefs(prefixAtom));
if (prefixAtom) { if (prefixAtom) {
const PRUnichar* prefix; nsAutoString prefix;
prefixAtom->GetUnicode(&prefix); prefixAtom->ToString(prefix);
aString.Append(prefix); aString.Append(prefix);
aString.Append(PRUnichar('|')); aString.Append(PRUnichar('|'));
} }
@ -648,15 +648,16 @@ nsresult nsCSSSelector::ToString( nsAString& aString, nsICSSStyleSheet* aSheet,
} else { } else {
// Append the tag name, if there is one // Append the tag name, if there is one
if (mTag) { if (mTag) {
mTag->GetUnicode(&temp); nsAutoString prefix;
aString.Append(temp); mTag->ToString(prefix);
aString.Append(prefix);
NS_IF_NEGATED_END(aIsNegated, aString) NS_IF_NEGATED_END(aIsNegated, aString)
} }
// Append the id, if there is one // Append the id, if there is one
if (mIDList) { if (mIDList) {
nsAtomList* list = mIDList; nsAtomList* list = mIDList;
while (list != nsnull) { while (list != nsnull) {
list->mAtom->GetUnicode(&temp); list->mAtom->ToString(temp);
NS_IF_NEGATED_START(aIsNegated, aString) NS_IF_NEGATED_START(aIsNegated, aString)
aString.Append(PRUnichar('#')); aString.Append(PRUnichar('#'));
aString.Append(temp); aString.Append(temp);
@ -668,7 +669,7 @@ nsresult nsCSSSelector::ToString( nsAString& aString, nsICSSStyleSheet* aSheet,
if (mClassList) { if (mClassList) {
nsAtomList* list = mClassList; nsAtomList* list = mClassList;
while (list != nsnull) { while (list != nsnull) {
list->mAtom->GetUnicode(&temp); list->mAtom->ToString(temp);
NS_IF_NEGATED_START(aIsNegated, aString) NS_IF_NEGATED_START(aIsNegated, aString)
aString.Append(PRUnichar('.')); aString.Append(PRUnichar('.'));
aString.Append(temp); aString.Append(temp);
@ -692,14 +693,14 @@ nsresult nsCSSSelector::ToString( nsAString& aString, nsICSSStyleSheet* aSheet,
// will return null if namespace was the default // will return null if namespace was the default
sheetNS->FindNameSpacePrefix(list->mNameSpace, *getter_AddRefs(prefixAtom)); sheetNS->FindNameSpacePrefix(list->mNameSpace, *getter_AddRefs(prefixAtom));
if (prefixAtom) { if (prefixAtom) {
const PRUnichar* prefix; nsAutoString prefix;
prefixAtom->GetUnicode(&prefix); prefixAtom->ToString(prefix);
aString.Append(prefix); aString.Append(prefix);
aString.Append(PRUnichar('|')); aString.Append(PRUnichar('|'));
} }
} }
// Append the attribute name // Append the attribute name
list->mAttr->GetUnicode(&temp); list->mAttr->ToString(temp);
aString.Append(temp); aString.Append(temp);
// Append the function // Append the function
if (list->mFunction == NS_ATTR_FUNC_EQUALS) { if (list->mFunction == NS_ATTR_FUNC_EQUALS) {
@ -732,7 +733,7 @@ nsresult nsCSSSelector::ToString( nsAString& aString, nsICSSStyleSheet* aSheet,
if (mPseudoClassList) { if (mPseudoClassList) {
nsAtomStringList* list = mPseudoClassList; nsAtomStringList* list = mPseudoClassList;
while (list != nsnull) { while (list != nsnull) {
list->mAtom->GetUnicode(&temp); list->mAtom->ToString(temp);
NS_IF_NEGATED_START(aIsNegated, aString) NS_IF_NEGATED_START(aIsNegated, aString)
aString.Append(temp); aString.Append(temp);
if (nsnull != list->mString) { if (nsnull != list->mString) {

View File

@ -168,12 +168,11 @@ RuleHash_CIMatchEntry(PLDHashTable *table, const PLDHashEntryHdr *hdr,
if (match_atom == entry_atom) if (match_atom == entry_atom)
return PR_TRUE; return PR_TRUE;
const PRUnichar *match_str, *entry_str; const char *match_str, *entry_str;
match_atom->GetUnicode(&match_str); match_atom->GetUTF8String(&match_str);
entry_atom->GetUnicode(&entry_str); entry_atom->GetUTF8String(&entry_str);
return nsDependentString(match_str).Equals(nsDependentString(entry_str), return (nsCRT::strcasecmp(entry_str, match_str) == 0);
nsCaseInsensitiveStringComparator());
} }
PR_STATIC_CALLBACK(PRBool) PR_STATIC_CALLBACK(PRBool)
@ -1116,8 +1115,8 @@ DOMMediaListImpl::GetText(nsAString& aMediaText)
QueryElementAt(index++, NS_GET_IID(nsIAtom), getter_AddRefs(medium)); QueryElementAt(index++, NS_GET_IID(nsIAtom), getter_AddRefs(medium));
NS_ENSURE_TRUE(medium, NS_ERROR_FAILURE); NS_ENSURE_TRUE(medium, NS_ERROR_FAILURE);
const PRUnichar *buffer; nsAutoString buffer;
medium->GetUnicode(&buffer); medium->ToString(buffer);
aMediaText.Append(buffer); aMediaText.Append(buffer);
if (index < count) { if (index < count) {
aMediaText.Append(NS_LITERAL_STRING(", ")); aMediaText.Append(NS_LITERAL_STRING(", "));
@ -1234,8 +1233,8 @@ DOMMediaListImpl::Item(PRUint32 aIndex, nsAString& aReturn)
nsCOMPtr<nsIAtom> medium(do_QueryInterface(tmp)); nsCOMPtr<nsIAtom> medium(do_QueryInterface(tmp));
NS_ENSURE_TRUE(medium, NS_ERROR_FAILURE); NS_ENSURE_TRUE(medium, NS_ERROR_FAILURE);
const PRUnichar *buffer; nsAutoString buffer;
medium->GetUnicode(&buffer); medium->ToString(buffer);
aReturn.Assign(buffer); aReturn.Assign(buffer);
} else { } else {
aReturn.Truncate(); aReturn.Truncate();
@ -3742,15 +3741,15 @@ static PRBool SelectorMatches(RuleProcessorData &data,
IDList = IDList->mNext; IDList = IDList->mNext;
} while (IDList); } while (IDList);
} else { } else {
const PRUnichar* id1Str; const char* id1Str;
data.mContentID->GetUnicode(&id1Str); data.mContentID->GetUTF8String(&id1Str);
nsDependentString id1(id1Str); nsDependentCString id1(id1Str);
do { do {
const PRUnichar* id2Str; const char* id2Str;
IDList->mAtom->GetUnicode(&id2Str); IDList->mAtom->GetUTF8String(&id2Str);
nsDependentString id2(id2Str); nsDependentCString id2(id2Str);
if (localTrue != if (localTrue !=
id1.Equals(id2, nsCaseInsensitiveStringComparator())) { id1.Equals(id2, nsCaseInsensitiveCStringComparator())) {
result = PR_FALSE; result = PR_FALSE;
break; break;
} }

View File

@ -64,7 +64,7 @@ var folderListener = {
//if we don't have a folder loaded, don't bother. //if we don't have a folder loaded, don't bother.
if (currentURI) { if (currentURI) {
if (property.GetUnicode() == "TotalMessages" || property.GetUnicode() == "TotalUnreadMessages") { if (property.toString() == "TotalMessages" || property.toString() == "TotalUnreadMessages") {
var folder = item.QueryInterface(Components.interfaces.nsIMsgFolder); var folder = item.QueryInterface(Components.interfaces.nsIMsgFolder);
if (folder) { if (folder) {
var folderResource = folder.QueryInterface(Components.interfaces.nsIRDFResource); var folderResource = folder.QueryInterface(Components.interfaces.nsIRDFResource);
@ -83,7 +83,7 @@ var folderListener = {
OnItemPropertyFlagChanged: function(item, property, oldFlag, newFlag) {}, OnItemPropertyFlagChanged: function(item, property, oldFlag, newFlag) {},
OnItemEvent: function(folder, event) { OnItemEvent: function(folder, event) {
var eventType = event.GetUnicode(); var eventType = event.toString();
if (eventType == "DeleteOrMoveMsgCompleted") if (eventType == "DeleteOrMoveMsgCompleted")
HandleDeleteOrMoveMsgCompleted(folder); HandleDeleteOrMoveMsgCompleted(folder);

View File

@ -105,7 +105,7 @@ var folderListener = {
//if we don't have a folder loaded, don't bother. //if we don't have a folder loaded, don't bother.
if(currentURI) { if(currentURI) {
if(property.GetUnicode() == "TotalMessages" || property.GetUnicode() == "TotalUnreadMessages") { if(property.toString() == "TotalMessages" || property.toString() == "TotalUnreadMessages") {
var folder = item.QueryInterface(Components.interfaces.nsIMsgFolder); var folder = item.QueryInterface(Components.interfaces.nsIMsgFolder);
if(folder) { if(folder) {
var folderResource = folder.QueryInterface(Components.interfaces.nsIRDFResource); var folderResource = folder.QueryInterface(Components.interfaces.nsIRDFResource);
@ -126,7 +126,7 @@ var folderListener = {
OnItemPropertyFlagChanged: function(item, property, oldFlag, newFlag) { }, OnItemPropertyFlagChanged: function(item, property, oldFlag, newFlag) { },
OnItemEvent: function(folder, event) { OnItemEvent: function(folder, event) {
var eventType = event.GetUnicode(); var eventType = event.toString();
if (eventType == "FolderLoaded") { if (eventType == "FolderLoaded") {
if (folder) { if (folder) {
var uri = folder.URI; var uri = folder.URI;

View File

@ -201,7 +201,7 @@ var gFolderListener = {
OnItemPropertyFlagChanged: function(item, property, oldFlag, newFlag) {}, OnItemPropertyFlagChanged: function(item, property, oldFlag, newFlag) {},
OnItemEvent: function(folder, event) { OnItemEvent: function(folder, event) {
var eventType = event.GetUnicode(); var eventType = event.toString();
if (eventType == "FolderCreateCompleted") { if (eventType == "FolderCreateCompleted") {
SetFolderPicker(folder.URI, gActionTargetElement.id); SetFolderPicker(folder.URI, gActionTargetElement.id);

View File

@ -193,8 +193,8 @@ var gFolderListener = {
OnItemPropertyFlagChanged: function(item, property, oldFlag, newFlag) {}, OnItemPropertyFlagChanged: function(item, property, oldFlag, newFlag) {},
OnItemEvent: function(folder, event) { OnItemEvent: function(folder, event) {
var eventType = event.GetUnicode(); var eventType = event.toString();
if (eventType == "DeleteOrMoveMsgCompleted") { if (eventType == "DeleteOrMoveMsgCompleted") {
HandleDeleteOrMoveMessageCompleted(folder); HandleDeleteOrMoveMessageCompleted(folder);
} }

View File

@ -607,8 +607,8 @@ nsresult nsMsgI18NSaveAsCharset(const char* contentType, const char *charset,
res = ccm2->GetCharsetAtom(NS_ConvertASCIItoUCS2(charset).get(), getter_AddRefs(charsetAtom)); res = ccm2->GetCharsetAtom(NS_ConvertASCIItoUCS2(charset).get(), getter_AddRefs(charsetAtom));
NS_ENSURE_SUCCESS(res, res); NS_ENSURE_SUCCESS(res, res);
const PRUnichar *charsetName; const char *charsetName;
res = charsetAtom->GetUnicode(&charsetName); res = charsetAtom->GetUTF8String(&charsetName);
NS_ENSURE_SUCCESS(res, res); NS_ENSURE_SUCCESS(res, res);
// charset converter plus entity, NCR generation // charset converter plus entity, NCR generation
@ -620,14 +620,14 @@ nsresult nsMsgI18NSaveAsCharset(const char* contentType, const char *charset,
// plain text - charset conv then fallback to '?' // plain text - charset conv then fallback to '?'
if (bTEXT_HTML) if (bTEXT_HTML)
// For ISO-8859-1 only, convert to entity first (always generate entites like &nbsp;). // For ISO-8859-1 only, convert to entity first (always generate entites like &nbsp;).
res = conv->Init(NS_ConvertUCS2toUTF8(charsetName).get(), res = conv->Init(charsetName,
!nsCRT::strcmp(charsetName, NS_LITERAL_STRING("ISO-8859-1").get()) ? !nsCRT::strcmp(charsetName, "ISO-8859-1") ?
nsISaveAsCharset::attr_htmlTextDefault : nsISaveAsCharset::attr_htmlTextDefault :
nsISaveAsCharset::attr_EntityAfterCharsetConv + nsISaveAsCharset::attr_FallbackDecimalNCR, nsISaveAsCharset::attr_EntityAfterCharsetConv + nsISaveAsCharset::attr_FallbackDecimalNCR,
nsIEntityConverter::html32); nsIEntityConverter::html32);
else else
// fallback for text/plain: first try transliterate then '?' // fallback for text/plain: first try transliterate then '?'
res = conv->Init(NS_ConvertUCS2toUTF8(charsetName).get(), res = conv->Init(charsetName,
nsISaveAsCharset::attr_FallbackQuestionMark + nsISaveAsCharset::attr_EntityAfterCharsetConv, nsISaveAsCharset::attr_FallbackQuestionMark + nsISaveAsCharset::attr_EntityAfterCharsetConv,
nsIEntityConverter::transliterate); nsIEntityConverter::transliterate);
NS_ENSURE_SUCCESS(res, res); NS_ENSURE_SUCCESS(res, res);
@ -636,7 +636,7 @@ nsresult nsMsgI18NSaveAsCharset(const char* contentType, const char *charset,
// Mapping characters in a certain range (required for Japanese only) // Mapping characters in a certain range (required for Japanese only)
nsAutoString mapped; nsAutoString mapped;
if (!nsCRT::strcmp(charsetName, NS_LITERAL_STRING("ISO-2022-JP").get())) { if (!nsCRT::strcmp(charsetName, "ISO-2022-JP")) {
static PRInt32 sSendHankakuKana = -1; static PRInt32 sSendHankakuKana = -1;
if (sSendHankakuKana < 0) { if (sSendHankakuKana < 0) {
nsCOMPtr<nsIPrefBranch> prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID, &res)); nsCOMPtr<nsIPrefBranch> prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID, &res));
@ -697,7 +697,7 @@ nsresult nsMsgI18NSaveAsCharset(const char* contentType, const char *charset,
// In case of HTML, non ASCII may be encoded as CER, NCR. // In case of HTML, non ASCII may be encoded as CER, NCR.
// Exclude stateful charset which is 7 bit but not ASCII only. // Exclude stateful charset which is 7 bit but not ASCII only.
else if (isAsciiOnly && bTEXT_HTML && *outString && else if (isAsciiOnly && bTEXT_HTML && *outString &&
!nsMsgI18Nstateful_charset(NS_LossyConvertUCS2toASCII(charsetName).get())) !nsMsgI18Nstateful_charset(charsetName))
*isAsciiOnly = nsCRT::IsAscii(*outString); *isAsciiOnly = nsCRT::IsAscii(*outString);
return res; return res;

View File

@ -1439,7 +1439,7 @@ function UpdateMailEditCharset()
if (gCharsetConvertManager) { if (gCharsetConvertManager) {
var charsetAtom = gCharsetConvertManager.GetCharsetAtom(compFieldsCharset); var charsetAtom = gCharsetConvertManager.GetCharsetAtom(compFieldsCharset);
if (charsetAtom && (charsetAtom.GetUnicode() == "us-ascii")) if (charsetAtom && (charsetAtom.equals("us-ascii")))
compFieldsCharset = "ISO-8859-1"; // no menu item for "us-ascii" compFieldsCharset = "ISO-8859-1"; // no menu item for "us-ascii"
} }

View File

@ -308,9 +308,9 @@ PRInt32 generate_encodedwords(char *pUTF8, const char *charset, char method, cha
nsMemory::Free(_pUCS2); nsMemory::Free(_pUCS2);
return -1; return -1;
} }
const PRUnichar *charsetName; const char *charsetName;
charsetAtom->GetUnicode(&charsetName); charsetAtom->GetUTF8String(&charsetName);
strncpy(_charset, NS_ConvertUCS2toUTF8(charsetName).get(), sizeof(_charset)-1); strncpy(_charset, charsetName, sizeof(_charset)-1);
_charset[sizeof(_charset)-1] = '\0'; _charset[sizeof(_charset)-1] = '\0';
if (_charset[0]) if (_charset[0])
charset = _charset; charset = _charset;

View File

@ -2062,7 +2062,6 @@ nsresult GetMailNewsFont(MimeObject *obj, PRBool styleFixed, PRInt32 *fontPixel
nsCOMPtr<nsICharsetConverterManager2> charSetConverterManager2; nsCOMPtr<nsICharsetConverterManager2> charSetConverterManager2;
nsCOMPtr <nsIAtom> charsetAtom; nsCOMPtr <nsIAtom> charsetAtom;
nsCOMPtr<nsIAtom> langGroupAtom; nsCOMPtr<nsIAtom> langGroupAtom;
const PRUnichar* langGroup = nsnull;
nsCAutoString prefStr; nsCAutoString prefStr;
ToLowerCase(charset); ToLowerCase(charset);
@ -2078,15 +2077,13 @@ nsresult GetMailNewsFont(MimeObject *obj, PRBool styleFixed, PRInt32 *fontPixel
rv = charSetConverterManager2->GetCharsetLangGroup(charsetAtom,getter_AddRefs(langGroupAtom)); rv = charSetConverterManager2->GetCharsetLangGroup(charsetAtom,getter_AddRefs(langGroupAtom));
if (NS_FAILED(rv)) if (NS_FAILED(rv))
return rv; return rv;
rv = langGroupAtom->GetUnicode(&langGroup); rv = langGroupAtom->ToUTF8String(fontLang);
if (NS_FAILED(rv)) if (NS_FAILED(rv))
return rv; return rv;
fontLang.AssignWithConversion(langGroup);
// get a font size from pref // get a font size from pref
prefStr.Assign(!styleFixed ? "font.size.variable." : "font.size.fixed."); prefStr.Assign(!styleFixed ? "font.size.variable." : "font.size.fixed.");
prefStr.AppendWithConversion(langGroup); prefStr.Append(fontLang);
rv = prefs->GetIntPref(prefStr.get(), fontPixelSize); rv = prefs->GetIntPref(prefStr.get(), fontPixelSize);
if (NS_FAILED(rv)) if (NS_FAILED(rv))
return rv; return rv;

View File

@ -44,11 +44,10 @@ NS_IMPL_ISUPPORTS1(nsParserService, nsIParserService)
NS_IMETHODIMP NS_IMETHODIMP
nsParserService::HTMLAtomTagToId(nsIAtom* aAtom, PRInt32* aId) const nsParserService::HTMLAtomTagToId(nsIAtom* aAtom, PRInt32* aId) const
{ {
const PRUnichar *tagName = nsnull; nsAutoString tagName;
aAtom->GetUnicode(&tagName); aAtom->ToString(tagName);
NS_ASSERTION(tagName, "Null string in atom!");
*aId = nsHTMLTags::LookupTag(nsDependentString(tagName)); *aId = nsHTMLTags::LookupTag(tagName);
return NS_OK; return NS_OK;
} }
@ -57,11 +56,10 @@ NS_IMETHODIMP
nsParserService::HTMLCaseSensitiveAtomTagToId(nsIAtom* aAtom, nsParserService::HTMLCaseSensitiveAtomTagToId(nsIAtom* aAtom,
PRInt32* aId) const PRInt32* aId) const
{ {
const PRUnichar *tagName = nsnull; nsAutoString tagName;
aAtom->GetUnicode(&tagName); aAtom->ToString(tagName);
NS_ASSERTION(tagName, "Null string in atom!");
*aId = nsHTMLTags::CaseSensitiveLookupTag(tagName); *aId = nsHTMLTags::CaseSensitiveLookupTag(tagName.get());
return NS_OK; return NS_OK;
} }

View File

@ -1105,17 +1105,17 @@ RDFContentSinkImpl::AddProperties(const PRUnichar** aAttributes,
nsAutoString v(aAttributes[1]); nsAutoString v(aAttributes[1]);
nsRDFParserUtils::StripAndConvert(v); nsRDFParserUtils::StripAndConvert(v);
const PRUnichar* attrName; const char* attrName;
attr->GetUnicode(&attrName); attr->GetUTF8String(&attrName);
nsCAutoString propertyStr; nsCAutoString propertyStr;
if (nameSpaceURI) { if (nameSpaceURI) {
propertyStr.Assign(nsDependentCString(nameSpaceURI) + propertyStr.Assign(nsDependentCString(nameSpaceURI) +
NS_ConvertUCS2toUTF8(attrName)); nsDependentCString(attrName));
} }
else { else {
propertyStr.Assign(NS_ConvertUCS2toUTF8(attrName)); propertyStr.Assign(attrName);
} }
// Add the assertion to RDF // Add the assertion to RDF
@ -1256,10 +1256,10 @@ RDFContentSinkImpl::OpenObject(const PRUnichar* aName,
if (nameSpaceURI) if (nameSpaceURI)
typeStr = nameSpaceURI; typeStr = nameSpaceURI;
const PRUnichar *attrName; const char* attrName;
tag->GetUnicode(&attrName); tag->GetUTF8String(&attrName);
typeStr += NS_ConvertUCS2toUTF8(attrName); typeStr += attrName;
nsCOMPtr<nsIRDFResource> type; nsCOMPtr<nsIRDFResource> type;
rv = gRDFService->GetResource(typeStr, getter_AddRefs(type)); rv = gRDFService->GetResource(typeStr, getter_AddRefs(type));
@ -1288,16 +1288,16 @@ RDFContentSinkImpl::OpenProperty(const PRUnichar* aName, const PRUnichar** aAttr
ParseTagString(aName, &nameSpaceURI, getter_AddRefs(tag)); ParseTagString(aName, &nameSpaceURI, getter_AddRefs(tag));
const PRUnichar *attrName; const char* attrName;
tag->GetUnicode(&attrName); tag->GetUTF8String(&attrName);
nsCAutoString propertyStr; nsCAutoString propertyStr;
if (nameSpaceURI) { if (nameSpaceURI) {
propertyStr.Assign(nsDependentCString(nameSpaceURI) + propertyStr.Assign(nsDependentCString(nameSpaceURI) +
NS_ConvertUCS2toUTF8(attrName)); nsDependentCString(attrName));
} }
else { else {
propertyStr.Assign(NS_ConvertUCS2toUTF8(attrName)); propertyStr.Assign(attrName);
} }
nsCOMPtr<nsIRDFResource> property; nsCOMPtr<nsIRDFResource> property;
@ -1467,17 +1467,14 @@ RDFContentSinkImpl::GetNameSpaceURI(nsIAtom* aPrefix, const char** aNameSpaceURI
#ifdef PR_LOGGING #ifdef PR_LOGGING
if (PR_LOG_TEST(gLog, PR_LOG_ALWAYS)) { if (PR_LOG_TEST(gLog, PR_LOG_ALWAYS)) {
nsAutoString prefixStr; const char* prefixStr;
if (aPrefix) if (aPrefix)
aPrefix->ToString(prefixStr); aPrefix->GetUTF8String(&prefixStr);
char* prefixCStr = ToNewCString(prefixStr);
PR_LOG(gLog, PR_LOG_ALWAYS, PR_LOG(gLog, PR_LOG_ALWAYS,
("rdfxml: undeclared namespace prefix '%s'", ("rdfxml: undeclared namespace prefix '%s'",
prefixCStr)); prefixStr));
nsCRT::free(prefixCStr);
} }
#endif #endif

View File

@ -229,12 +229,12 @@ STDMETHODIMP SimpleDOMNode::get_attributes(
for (index = 0; index < numAttribs; index++) { for (index = 0; index < numAttribs; index++) {
aNameSpaceIDs[index] = 0; aAttribValues[index] = aAttribNames[index] = nsnull; aNameSpaceIDs[index] = 0; aAttribValues[index] = aAttribNames[index] = nsnull;
nsAutoString attributeValue; nsAutoString attributeValue;
const PRUnichar *pszAttributeName; const char *pszAttributeName;
if (NS_SUCCEEDED(content->GetAttrNameAt(index, nameSpaceID, *getter_AddRefs(nameAtom), *getter_AddRefs(prefixAtom)))) { if (NS_SUCCEEDED(content->GetAttrNameAt(index, nameSpaceID, *getter_AddRefs(nameAtom), *getter_AddRefs(prefixAtom)))) {
aNameSpaceIDs[index] = NS_STATIC_CAST(short, nameSpaceID); aNameSpaceIDs[index] = NS_STATIC_CAST(short, nameSpaceID);
nameAtom->GetUnicode(&pszAttributeName); nameAtom->GetUTF8String(&pszAttributeName);
aAttribNames[index] = ::SysAllocString(pszAttributeName); aAttribNames[index] = ::SysAllocString(NS_ConvertUTF8toUCS2(pszAttributeName).get());
if (NS_SUCCEEDED(content->GetAttr(nameSpaceID, nameAtom, attributeValue))) if (NS_SUCCEEDED(content->GetAttr(nameSpaceID, nameAtom, attributeValue)))
aAttribValues[index] = ::SysAllocString(attributeValue.get()); aAttribValues[index] = ::SysAllocString(attributeValue.get());
} }

View File

@ -37,10 +37,18 @@
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
#include "nsAtomTable.h" #include "nsAtomTable.h"
#include "nsStaticAtom.h"
#include "nsString.h" #include "nsString.h"
#include "nsReadableUtils.h"
#include "nsCRT.h" #include "nsCRT.h"
#include "pldhash.h" #include "pldhash.h"
#include "prenv.h" #include "prenv.h"
#include "nsVoidArray.h"
#define PL_ARENA_CONST_ALIGN_MASK 3
#include "plarena.h"
class nsStaticAtomWrapper;
/** /**
* The shared hash table for atom lookups. * The shared hash table for atom lookups.
@ -53,29 +61,117 @@
*/ */
static PLDHashTable gAtomTable; static PLDHashTable gAtomTable;
// this is where we keep the nsStaticAtomWrapper objects
static PLArenaPool* gStaticAtomArena = 0;
class nsStaticAtomWrapper : public nsIAtom
{
public:
nsStaticAtomWrapper(const nsStaticAtom* aAtom) :
mStaticAtom(aAtom)
{
MOZ_COUNT_CTOR(nsStaticAtomWrapper);
}
virtual ~nsStaticAtomWrapper() {
// this is arena allocated and won't be called except in debug
// builds. If this function ever does anything non-debug, be sure
// to get rid of the ifdefs in AtomTableClearEntry!
MOZ_COUNT_DTOR(nsStaticAtomWrapper);
}
NS_IMETHOD QueryInterface(REFNSIID aIID,
void** aInstancePtr);
NS_IMETHOD_(nsrefcnt) AddRef(void);
NS_IMETHOD_(nsrefcnt) Release(void);
NS_DECL_NSIATOM
const nsStaticAtom* GetStaticAtom() {
return mStaticAtom;
}
private:
const nsStaticAtom* mStaticAtom;
};
// the atomtableentry can contain either an AtomImpl or a
// nsStaticAtomWrapper, indicated by the first bit of PtrBits
typedef unsigned long PtrBits;
struct AtomTableEntry : public PLDHashEntryHdr { struct AtomTableEntry : public PLDHashEntryHdr {
AtomImpl *mAtom; // mAtom & 0x1 means (mAtom & ~0x1) points to an nsStaticAtomWrapper
// else it points to an nsAtomImpl
PtrBits mAtom;
inline PRBool IsStaticAtom() const {
return (mAtom & 0x1) != 0;
}
inline void SetAtomImpl(AtomImpl* aAtom) {
NS_ASSERTION(aAtom, "Setting null atom");
mAtom = PtrBits(aAtom);
}
inline void SetStaticAtomWrapper(nsStaticAtomWrapper* aAtom) {
NS_ASSERTION(aAtom, "Setting null atom");
NS_ASSERTION((PtrBits(aAtom) & ~0x1) == PtrBits(aAtom),
"Pointers must align or this is broken");
mAtom = PtrBits(aAtom) | 0x1;
}
inline void ClearAtom() {
mAtom = nsnull;
}
inline PRBool HasValue() const {
return (mAtom & ~0x1) != 0;
}
// these accessors assume that you already know the type
inline AtomImpl *GetAtomImpl() const {
NS_ASSERTION(!IsStaticAtom(), "This is a static atom, not an AtomImpl");
return (AtomImpl*) (mAtom & ~0x1);
}
inline nsStaticAtomWrapper *GetStaticAtomWrapper() const {
NS_ASSERTION(IsStaticAtom(), "This is an AtomImpl, not a static atom");
return (nsStaticAtomWrapper*) (mAtom & ~0x1);
}
inline const nsStaticAtom* GetStaticAtom() const {
return GetStaticAtomWrapper()->GetStaticAtom();
}
// type-agnostic accessors
// get the string buffer
inline const char* get() const {
return IsStaticAtom() ? GetStaticAtom()->mString : GetAtomImpl()->mString;
}
// get an addreffed nsIAtom - not using already_AddRef'ed atom
// because the callers are not (and should not be) using nsCOMPtr
inline nsIAtom* GetAtom() const {
nsIAtom* result;
if (IsStaticAtom())
result = GetStaticAtomWrapper();
else {
result = GetAtomImpl();
NS_ADDREF(result);
}
return result;
}
}; };
PR_STATIC_CALLBACK(const void *) PR_STATIC_CALLBACK(const void *)
AtomTableGetKey(PLDHashTable *table, PLDHashEntryHdr *entry) AtomTableGetKey(PLDHashTable *table, PLDHashEntryHdr *entry)
{ {
AtomTableEntry *he = NS_STATIC_CAST(AtomTableEntry*, entry); AtomTableEntry *he = NS_STATIC_CAST(AtomTableEntry*, entry);
return he->mAtom->mString; NS_ASSERTION(he->HasValue(), "Empty atom. how did that happen?");
} return he->get();
PR_STATIC_CALLBACK(PLDHashNumber)
AtomTableHashKey(PLDHashTable *table, const void *key)
{
const PRUnichar *str = NS_STATIC_CAST(const PRUnichar*, key);
if (!str) {
static const PRUnichar empty_buffer[] = {0};
str = empty_buffer;
}
return nsCRT::HashCode(str);
} }
PR_STATIC_CALLBACK(PRBool) PR_STATIC_CALLBACK(PRBool)
@ -84,33 +180,43 @@ AtomTableMatchKey(PLDHashTable *table,
const void *key) const void *key)
{ {
const AtomTableEntry *he = NS_STATIC_CAST(const AtomTableEntry*, entry); const AtomTableEntry *he = NS_STATIC_CAST(const AtomTableEntry*, entry);
const PRUnichar* keyStr = NS_STATIC_CAST(const PRUnichar*, key); const char* keyStr = NS_STATIC_CAST(const char*, key);
return nsCRT::strcmp(keyStr, he->mAtom->mString) == 0; return nsCRT::strcmp(keyStr, he->get()) == 0;
} }
PR_STATIC_CALLBACK(void) PR_STATIC_CALLBACK(void)
AtomTableClearEntry(PLDHashTable *table, PLDHashEntryHdr *entry) AtomTableClearEntry(PLDHashTable *table, PLDHashEntryHdr *entry)
{ {
AtomTableEntry *he = NS_STATIC_CAST(AtomTableEntry*, entry); AtomTableEntry *he = NS_STATIC_CAST(AtomTableEntry*, entry);
AtomImpl *atom = he->mAtom;
he->mAtom = 0;
he->keyHash = 0; he->keyHash = 0;
// Normal |AtomImpl| atoms are deleted when their refcount hits 0, and if (!he->IsStaticAtom()) {
// they then remove themselves from the table. In other words, they AtomImpl *atom = he->GetAtomImpl();
// are owned by the callers who own references to them. // Normal |AtomImpl| atoms are deleted when their refcount hits 0, and
// |PermanentAtomImpl| permanent atoms ignore their refcount and are // they then remove themselves from the table. In other words, they
// deleted when they are removed from the table at table destruction. // are owned by the callers who own references to them.
// In other words, they are owned by the atom table. // |PermanentAtomImpl| permanent atoms ignore their refcount and are
if (atom->IsPermanent()) // deleted when they are removed from the table at table destruction.
delete atom; // In other words, they are owned by the atom table.
if (atom->IsPermanent())
delete atom;
}
#ifdef NS_DEBUG
// this is debug-only mostly for bloat logs
else {
he->GetStaticAtomWrapper()->~nsStaticAtomWrapper();
}
#endif
he->ClearAtom();
} }
static PLDHashTableOps AtomTableOps = { static PLDHashTableOps AtomTableOps = {
PL_DHashAllocTable, PL_DHashAllocTable,
PL_DHashFreeTable, PL_DHashFreeTable,
AtomTableGetKey, AtomTableGetKey,
AtomTableHashKey, PL_DHashStringKey,
AtomTableMatchKey, AtomTableMatchKey,
PL_DHashMoveEntryStub, PL_DHashMoveEntryStub,
AtomTableClearEntry, AtomTableClearEntry,
@ -126,12 +232,16 @@ DumpAtomLeaks(PLDHashTable *table, PLDHashEntryHdr *he,
PRUint32 index, void *arg) PRUint32 index, void *arg)
{ {
AtomTableEntry *entry = NS_STATIC_CAST(AtomTableEntry*, he); AtomTableEntry *entry = NS_STATIC_CAST(AtomTableEntry*, he);
AtomImpl* atom = entry->mAtom;
if (entry->IsStaticAtom())
return PL_DHASH_NEXT;
AtomImpl* atom = entry->GetAtomImpl();
if (!atom->IsPermanent()) { if (!atom->IsPermanent()) {
++*NS_STATIC_CAST(PRUint32*, arg); ++*NS_STATIC_CAST(PRUint32*, arg);
const PRUnichar *str; const char *str;
atom->GetUnicode(&str); atom->GetUTF8String(&str);
fputs(NS_LossyConvertUCS2toASCII(str).get(), stdout); fputs(str, stdout);
fputs("\n", stdout); fputs("\n", stdout);
} }
return PL_DHASH_NEXT; return PL_DHASH_NEXT;
@ -139,6 +249,20 @@ DumpAtomLeaks(PLDHashTable *table, PLDHashEntryHdr *he,
#endif #endif
static inline
void PromoteToPermanent(AtomImpl* aAtom)
{
#ifdef NS_BUILD_REFCNT_LOGGING
{
nsrefcnt refcount = aAtom->GetRefCount();
do {
NS_LOG_RELEASE(aAtom, --refcount, "AtomImpl");
} while (refcount);
}
#endif
aAtom = new (aAtom) PermanentAtomImpl();
}
void NS_PurgeAtomTable() void NS_PurgeAtomTable()
{ {
if (gAtomTable.entryCount) { if (gAtomTable.entryCount) {
@ -153,6 +277,12 @@ void NS_PurgeAtomTable()
#endif #endif
PL_DHashTableFinish(&gAtomTable); PL_DHashTableFinish(&gAtomTable);
gAtomTable.entryCount = 0; gAtomTable.entryCount = 0;
if (gStaticAtomArena) {
PL_FinishArenaPool(gStaticAtomArena);
delete gStaticAtomArena;
gStaticAtomArena = nsnull;
}
} }
} }
@ -200,7 +330,7 @@ PermanentAtomImpl::IsPermanent()
return PR_TRUE; return PR_TRUE;
} }
void* AtomImpl::operator new ( size_t size, const nsAString& aString ) CPP_THROW_NEW void* AtomImpl::operator new ( size_t size, const nsACString& aString ) CPP_THROW_NEW
{ {
/* /*
Note: since the |size| will initially also include the |PRUnichar| member Note: since the |size| will initially also include the |PRUnichar| member
@ -211,12 +341,12 @@ void* AtomImpl::operator new ( size_t size, const nsAString& aString ) CPP_THROW
compiler. A more reliable scheme is used by |nsShared[C]String|s, see compiler. A more reliable scheme is used by |nsShared[C]String|s, see
http://lxr.mozilla.org/seamonkey/source/xpcom/ds/nsSharedString.h#174 http://lxr.mozilla.org/seamonkey/source/xpcom/ds/nsSharedString.h#174
*/ */
size += aString.Length() * sizeof(PRUnichar); size += aString.Length() * sizeof(char);
AtomImpl* ii = NS_STATIC_CAST(AtomImpl*, ::operator new(size)); AtomImpl* ii = NS_STATIC_CAST(AtomImpl*, ::operator new(size));
PRUnichar* toBegin = &ii->mString[0]; char* toBegin = &ii->mString[0];
nsReadingIterator<PRUnichar> fromBegin, fromEnd; nsACString::const_iterator fromBegin, fromEnd;
*copy_string(aString.BeginReading(fromBegin), aString.EndReading(fromEnd), toBegin) = PRUnichar(0); *copy_string(aString.BeginReading(fromBegin), aString.EndReading(fromEnd), toBegin) = '\0';
return ii; return ii;
} }
@ -229,25 +359,102 @@ void* PermanentAtomImpl::operator new ( size_t size, AtomImpl* aAtom ) CPP_THROW
} }
NS_IMETHODIMP NS_IMETHODIMP
AtomImpl::ToString(nsAString& aBuf) /*FIX: const */ AtomImpl::ToString(nsAString& aBuf)
{
aBuf.Assign(NS_ConvertUTF8toUCS2(mString));
return NS_OK;
}
NS_IMETHODIMP
AtomImpl::ToUTF8String(nsACString& aBuf)
{ {
aBuf.Assign(mString); aBuf.Assign(mString);
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP NS_IMETHODIMP
AtomImpl::GetUnicode(const PRUnichar **aResult) /*FIX: const */ AtomImpl::GetUTF8String(const char **aResult)
{ {
NS_PRECONDITION(aResult, "null out param"); NS_PRECONDITION(aResult, "null out param");
*aResult = mString; *aResult = mString;
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP
AtomImpl::EqualsUTF8(const nsACString& aString, PRBool* aResult)
{
*aResult = aString.Equals(mString);
return NS_OK;
}
NS_IMETHODIMP
AtomImpl::Equals(const nsAString& aString, PRBool* aResult)
{
*aResult = NS_ConvertUCS2toUTF8(aString).Equals(mString);
return NS_OK;
}
//----------------------------------------------------------------------
// wrapper class for the nsStaticAtom struct
NS_IMETHODIMP_(nsrefcnt)
nsStaticAtomWrapper::AddRef()
{
return 2;
}
NS_IMETHODIMP_(nsrefcnt)
nsStaticAtomWrapper::Release()
{
return 1;
}
NS_IMPL_QUERY_INTERFACE1(nsStaticAtomWrapper, nsIAtom)
NS_IMETHODIMP
nsStaticAtomWrapper::GetUTF8String(const char** aResult)
{
*aResult = mStaticAtom->mString;
return NS_OK;
}
NS_IMETHODIMP
nsStaticAtomWrapper::ToString(nsAString& aBuf)
{
// static should always be always ASCII, to allow tools like gperf
// to generate the tables, and to avoid unnecessary conversion
NS_ASSERTION(nsCRT::IsAscii(mStaticAtom->mString),
"Data loss - atom should be ASCII");
CopyASCIItoUCS2(nsDependentCString(mStaticAtom->mString), aBuf);
return NS_OK;
}
NS_IMETHODIMP
nsStaticAtomWrapper::ToUTF8String(nsACString& aBuf)
{
aBuf.Assign(mStaticAtom->mString);
return NS_OK;
}
NS_IMETHODIMP
nsStaticAtomWrapper::EqualsUTF8(const nsACString& aString, PRBool* aResult)
{
*aResult = aString.Equals(mStaticAtom->mString);
return NS_OK;
}
NS_IMETHODIMP
nsStaticAtomWrapper::Equals(const nsAString& aString, PRBool* aResult)
{
*aResult = NS_ConvertUCS2toUTF8(aString).Equals(mStaticAtom->mString);
return NS_OK;
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
NS_COM nsIAtom* NS_NewAtom(const char* isolatin1) NS_COM nsIAtom* NS_NewAtom(const char* isolatin1)
{ {
return NS_NewAtom(NS_ConvertASCIItoUCS2(isolatin1)); return NS_NewAtom(nsDependentCString(isolatin1));
} }
NS_COM nsIAtom* NS_NewPermanentAtom(const char* isolatin1) NS_COM nsIAtom* NS_NewPermanentAtom(const char* isolatin1)
@ -255,7 +462,27 @@ NS_COM nsIAtom* NS_NewPermanentAtom(const char* isolatin1)
return NS_NewPermanentAtom(NS_ConvertASCIItoUCS2(isolatin1)); return NS_NewPermanentAtom(NS_ConvertASCIItoUCS2(isolatin1));
} }
static AtomTableEntry* GetAtomHashEntry(const nsAString& aString) static nsStaticAtomWrapper*
WrapStaticAtom(const nsStaticAtom* aAtom)
{
if (!gStaticAtomArena) {
gStaticAtomArena = new PLArenaPool;
if (!gStaticAtomArena)
return nsnull;
PL_INIT_ARENA_POOL(gStaticAtomArena, "nsStaticAtomArena", 4096);
}
void* mem;
PL_ARENA_ALLOCATE(mem, gStaticAtomArena, sizeof(nsStaticAtom));
nsStaticAtomWrapper* wrapper =
new (mem) nsStaticAtomWrapper(aAtom);
return wrapper;
}
static AtomTableEntry* GetAtomHashEntry(const char* aString)
{ {
if ( !gAtomTable.entryCount ) if ( !gAtomTable.entryCount )
PL_DHashTableInit(&gAtomTable, &AtomTableOps, 0, PL_DHashTableInit(&gAtomTable, &AtomTableOps, 0,
@ -263,22 +490,73 @@ static AtomTableEntry* GetAtomHashEntry(const nsAString& aString)
return NS_STATIC_CAST(AtomTableEntry*, return NS_STATIC_CAST(AtomTableEntry*,
PL_DHashTableOperate(&gAtomTable, PL_DHashTableOperate(&gAtomTable,
PromiseFlatString(aString).get(), aString,
PL_DHASH_ADD)); PL_DHASH_ADD));
} }
NS_COM nsresult
NS_RegisterStaticAtoms(const nsStaticAtom* aAtoms, PRUint32 aAtomCount)
{
// this does two things:
// 1) wraps each static atom in a wrapper, if necessary
// 2) initializes the address pointed to by each mAtom slot
for (PRUint32 i=0; i<aAtomCount; i++) {
NS_ASSERTION(nsCRT::IsAscii(aAtoms[i].mString),
"Static atoms must be ASCII!");
AtomTableEntry *he =
GetAtomHashEntry(aAtoms[i].mString);
if (he->HasValue() && aAtoms[i].mAtom) {
// there already is an atom with this name in the table.. but we
// still have to update mAtom
if (!he->IsStaticAtom() && !he->GetAtomImpl()->IsPermanent()) {
// since we wanted to create a static atom but there is
// already one there, we convert it to a non-refcounting
// permanent atom
PromoteToPermanent(he->GetAtomImpl());
}
// and now, if the consumer wants to remember this value in a
// slot, we do so
if (aAtoms[i].mAtom)
*aAtoms[i].mAtom = he->GetAtom();
}
else {
nsStaticAtomWrapper* atom = WrapStaticAtom(&aAtoms[i]);
NS_ASSERTION(atom, "Failed to wrap static atom");
// but even if atom is null, no real difference in code..
he->SetStaticAtomWrapper(atom);
if (aAtoms[i].mAtom)
*aAtoms[i].mAtom = atom;
}
}
return NS_OK;
}
NS_COM nsIAtom* NS_NewAtom( const nsAString& aString ) NS_COM nsIAtom* NS_NewAtom( const nsAString& aString )
{ {
AtomTableEntry *he = GetAtomHashEntry(aString); NS_ConvertUCS2toUTF8 utf8String(aString);
AtomImpl* atom = he->mAtom;
return NS_NewAtom(utf8String);
}
NS_COM
nsIAtom*
NS_NewAtom( const nsACString& aString )
{
AtomTableEntry *he = GetAtomHashEntry(PromiseFlatCString(aString).get());
if (he->HasValue())
return he->GetAtom();
AtomImpl* atom = new (aString) AtomImpl();
he->SetAtomImpl(atom);
if (!atom) { if (!atom) {
atom = new (aString) AtomImpl(); PL_DHashTableRawRemove(&gAtomTable, he);
he->mAtom = atom; return nsnull;
if (!atom) {
PL_DHashTableRawRemove(&gAtomTable, he);
return nsnull;
}
} }
NS_ADDREF(atom); NS_ADDREF(atom);
@ -287,26 +565,30 @@ NS_COM nsIAtom* NS_NewAtom( const nsAString& aString )
NS_COM nsIAtom* NS_NewPermanentAtom( const nsAString& aString ) NS_COM nsIAtom* NS_NewPermanentAtom( const nsAString& aString )
{ {
AtomTableEntry *he = GetAtomHashEntry(aString); return NS_NewPermanentAtom(NS_ConvertUCS2toUTF8(aString));
AtomImpl* atom = he->mAtom; }
NS_COM
nsIAtom* NS_NewPermanentAtom( const nsACString& aString )
{
AtomTableEntry *he = GetAtomHashEntry(PromiseFlatCString(aString).get());
if (he->HasValue() && he->IsStaticAtom())
return he->GetStaticAtomWrapper();
// either there is no atom and we'll create an AtomImpl,
// or there is an existing AtomImpl
AtomImpl* atom = he->GetAtomImpl();
if (atom) { if (atom) {
// ensure that it's permanent // ensure that it's permanent
if (!atom->IsPermanent()) { if (!atom->IsPermanent()) {
#ifdef NS_BUILD_REFCNT_LOGGING PromoteToPermanent(atom);
{
nsrefcnt refcount = atom->GetRefCount();
do {
NS_LOG_RELEASE(atom, --refcount, "AtomImpl");
} while (refcount);
}
#endif
atom = new (atom) PermanentAtomImpl();
} }
} else { } else {
// otherwise, make a new atom // otherwise, make a new atom
atom = new (aString) PermanentAtomImpl(); atom = new (aString) PermanentAtomImpl();
he->mAtom = atom; he->SetAtomImpl(atom);
if ( !atom ) { if ( !atom ) {
PL_DHashTableRawRemove(&gAtomTable, he); PL_DHashTableRawRemove(&gAtomTable, he);
return nsnull; return nsnull;
@ -319,7 +601,7 @@ NS_COM nsIAtom* NS_NewPermanentAtom( const nsAString& aString )
NS_COM nsIAtom* NS_NewAtom( const PRUnichar* str ) NS_COM nsIAtom* NS_NewAtom( const PRUnichar* str )
{ {
return NS_NewAtom(nsDependentString(str)); return NS_NewAtom(NS_ConvertUCS2toUTF8(str));
} }
NS_COM nsIAtom* NS_NewPermanentAtom( const PRUnichar* str ) NS_COM nsIAtom* NS_NewPermanentAtom( const PRUnichar* str )
@ -331,3 +613,4 @@ NS_COM nsrefcnt NS_GetNumberOfAtoms(void)
{ {
return gAtomTable.entryCount; return gAtomTable.entryCount;
} }

View File

@ -56,7 +56,7 @@ public:
virtual PRBool IsPermanent(); virtual PRBool IsPermanent();
void* operator new(size_t size, const nsAString& aString) CPP_THROW_NEW; void* operator new(size_t size, const nsACString& aString) CPP_THROW_NEW;
void operator delete(void* ptr) { void operator delete(void* ptr) {
::operator delete(ptr); ::operator delete(ptr);
@ -67,7 +67,7 @@ public:
// Actually more; 0 terminated. This slot is reserved for the // Actually more; 0 terminated. This slot is reserved for the
// terminating zero. // terminating zero.
PRUnichar mString[1]; char mString[1];
}; };
/** /**
@ -84,7 +84,7 @@ public:
virtual PRBool IsPermanent(); virtual PRBool IsPermanent();
void* operator new(size_t size, const nsAString& aString) CPP_THROW_NEW { void* operator new(size_t size, const nsACString& aString) CPP_THROW_NEW {
return AtomImpl::operator new(size, aString); return AtomImpl::operator new(size, aString);
} }
void* operator new(size_t size, AtomImpl* aAtom) CPP_THROW_NEW; void* operator new(size_t size, AtomImpl* aAtom) CPP_THROW_NEW;

View File

@ -38,14 +38,39 @@
interface nsIAtom : nsISupports interface nsIAtom : nsISupports
{ {
/** /**
* Translate the unicode string into the stringbuf. * Get the Unicode or UTF8 value for the string
*/ */
[noscript] AString toString(); AString toString();
AUTF8String toUTF8String();
/** /**
* Return a pointer to a zero terminated unicode string. * Return a pointer to a zero terminated UTF8 string.
*/ */
void GetUnicode([shared, retval] out wstring aResult); [noscript] void getUTF8String([shared, retval] out string aResult);
/**
* Compare the atom to a specific string value
* Note that this will NEVER return/throw an error condition.
*/
boolean equals(in AString aString);
boolean equalsUTF8(in AUTF8String aString);
%{C++
// note this is NOT virtual so this won't muck with the vtable!
inline PRBool Equals(const nsAString& s) {
PRBool result;
Equals(s, &result);
return result;
}
inline PRBool EqualsUTF8(const nsACString& s) {
PRBool result;
EqualsUTF8(s, &result);
return result;
}
%}
}; };
@ -71,13 +96,20 @@ interface nsIAtom : nsISupports
* Find an atom that matches the given ISO-Latin1 C string. The * Find an atom that matches the given ISO-Latin1 C string. The
* C string is translated into its unicode equivalent. * C string is translated into its unicode equivalent.
*/ */
extern NS_COM nsIAtom* NS_NewAtom(const char* isolatin1); extern NS_COM nsIAtom* NS_NewAtom(const char* utf8String);
extern NS_COM nsIAtom* NS_NewPermanentAtom(const char* isolatin1); extern NS_COM nsIAtom* NS_NewAtom(const nsACString& utf8String);
extern NS_COM nsIAtom* NS_NewPermanentAtom(const char* utf8String);
extern NS_COM nsIAtom* NS_NewPermanentAtom(const nsACString& utf8String);
inline already_AddRefed<nsIAtom> do_GetAtom(const char* isolatin1) inline already_AddRefed<nsIAtom> do_GetAtom(const char* utf8String)
{ return NS_NewAtom(isolatin1); } { return NS_NewAtom(utf8String); }
inline already_AddRefed<nsIAtom> do_GetPermanentAtom(const char* isolatin1) inline already_AddRefed<nsIAtom> do_GetAtom(const nsACString& utf8String)
{ return NS_NewPermanentAtom(isolatin1); } { return NS_NewAtom(utf8String); }
inline already_AddRefed<nsIAtom> do_GetPermanentAtom(const char* utf8String)
{ return NS_NewPermanentAtom(utf8String); }
inline already_AddRefed<nsIAtom> do_GetPermanentAtom(const nsACString& utf8String)
{ return NS_NewPermanentAtom(utf8String); }
/** /**
* Find an atom that matches the given unicode string. The string is assumed * Find an atom that matches the given unicode string. The string is assumed

View File

@ -81,9 +81,9 @@ int main(int argc, char** argv)
// Now make sure we can find all the idents we just made // Now make sure we can find all the idents we just made
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
const PRUnichar *unicodeString; const char *utf8String;
ids[i]->GetUnicode(&unicodeString); ids[i]->GetUTF8String(&utf8String);
nsIAtom* id = NS_NewAtom(unicodeString); nsIAtom* id = NS_NewAtom(utf8String);
if (id != ids[i]) { if (id != ids[i]) {
id->ToString(s1); id->ToString(s1);
ids[i]->ToString(s2); ids[i]->ToString(s2);

View File

@ -49,11 +49,11 @@ static void Assert(PRBool aCondition, const char* aStatement)
printf("%s: %s\n", aCondition?"PASS":"FAIL", aStatement); printf("%s: %s\n", aCondition?"PASS":"FAIL", aStatement);
} }
static void AssertString(nsIAtom *aAtom, const nsAString& aString) static void AssertString(nsIAtom *aAtom, const nsACString& aString)
{ {
const PRUnichar *str; const char *str;
NS_STATIC_CAST(AtomImpl*,aAtom)->GetUnicode(&str); NS_STATIC_CAST(AtomImpl*,aAtom)->GetUTF8String(&str);
Assert(nsDependentString(str) == aString, "string is correct"); Assert(nsDependentCString(str) == aString, "string is correct");
} }
static void AssertPermanence(nsIAtom *aAtom, PRBool aPermanence) static void AssertPermanence(nsIAtom *aAtom, PRBool aPermanence)
@ -65,21 +65,21 @@ static void AssertPermanence(nsIAtom *aAtom, PRBool aPermanence)
int main() int main()
{ {
nsCOMPtr<nsIAtom> foo = do_GetAtom("foo"); nsCOMPtr<nsIAtom> foo = do_GetAtom("foo");
AssertString(foo, NS_LITERAL_STRING("foo")); AssertString(foo, NS_LITERAL_CSTRING("foo"));
AssertPermanence(foo, PR_FALSE); AssertPermanence(foo, PR_FALSE);
nsCOMPtr<nsIAtom> foop = do_GetPermanentAtom("foo"); nsCOMPtr<nsIAtom> foop = do_GetPermanentAtom("foo");
AssertString(foop, NS_LITERAL_STRING("foo")); AssertString(foop, NS_LITERAL_CSTRING("foo"));
AssertPermanence(foop, PR_TRUE); AssertPermanence(foop, PR_TRUE);
Assert(foo == foop, "atoms are equal"); Assert(foo == foop, "atoms are equal");
nsCOMPtr<nsIAtom> barp = do_GetPermanentAtom("bar"); nsCOMPtr<nsIAtom> barp = do_GetPermanentAtom("bar");
AssertString(barp, NS_LITERAL_STRING("bar")); AssertString(barp, NS_LITERAL_CSTRING("bar"));
AssertPermanence(barp, PR_TRUE); AssertPermanence(barp, PR_TRUE);
nsCOMPtr<nsIAtom> bar = do_GetAtom("bar"); nsCOMPtr<nsIAtom> bar = do_GetAtom("bar");
AssertString(bar, NS_LITERAL_STRING("bar")); AssertString(bar, NS_LITERAL_CSTRING("bar"));
AssertPermanence(bar, PR_TRUE); AssertPermanence(bar, PR_TRUE);
Assert(bar == barp, "atoms are equal"); Assert(bar == barp, "atoms are equal");