Bug 870698 - Part 9: Replace Assign(NS_LITERAL_STRING("")) with AssignLiteral(u""). r=erahm

The NS_LITERAL_STRING macro creates a temporary nsLiteralString to encapsulate the char16_t string literal and its length, but AssignLiteral() can determine the char16_t string literal's length at compile-time without nsLiteralString.

MozReview-Commit-ID: 6vgQiU8zN3o

--HG--
extra : rebase_source : 1b536b92ef43f610db057ace6f108620e8d8b4d5
extra : source : 336e21386d5eeb16f1c9893c29377f23b67cc4b0
This commit is contained in:
Chris Peterson 2017-09-06 01:43:13 -07:00
parent 1ca3d5aa46
commit 210c7f9690
5 changed files with 26 additions and 26 deletions

View File

@ -47,9 +47,9 @@ bool ContainNonWordCharacter(const nsAString& aStr)
void GetPrefix(const nsINode* aNode, nsAString& aResult)
{
if (aNode->IsXULElement()) {
aResult.Assign(NS_LITERAL_STRING("xul"));
aResult.AssignLiteral(u"xul");
} else if (aNode->IsHTMLElement()) {
aResult.Assign(NS_LITERAL_STRING("xhtml"));
aResult.AssignLiteral(u"xhtml");
}
}
@ -187,7 +187,7 @@ void XPathGenerator::Generate(const nsINode* aNode, nsAString& aResult)
namePart.Assign(NS_LITERAL_STRING("[@name=") + quotedArgument + NS_LITERAL_STRING("]"));
}
if (count != 1) {
countPart.Assign(NS_LITERAL_STRING("["));
countPart.AssignLiteral(u"[");
countPart.AppendInt(count);
countPart.Append(NS_LITERAL_STRING("]"));
}

View File

@ -11,10 +11,10 @@
TEST(TestXPathGenerator, TestQuoteArgumentWithoutQuote)
{
nsAutoString arg;
arg.Assign(NS_LITERAL_STRING("testing"));
arg.AssignLiteral(u"testing");
nsAutoString expectedResult;
expectedResult.Assign(NS_LITERAL_STRING("\'testing\'"));
expectedResult.AssignLiteral(u"\'testing\'");
nsAutoString result;
XPathGenerator::QuoteArgument(arg, result);
@ -25,10 +25,10 @@ TEST(TestXPathGenerator, TestQuoteArgumentWithoutQuote)
TEST(TestXPathGenerator, TestQuoteArgumentWithSingleQuote)
{
nsAutoString arg;
arg.Assign(NS_LITERAL_STRING("\'testing\'"));
arg.AssignLiteral(u"\'testing\'");
nsAutoString expectedResult;
expectedResult.Assign(NS_LITERAL_STRING("\"\'testing\'\""));
expectedResult.AssignLiteral(u"\"\'testing\'\"");
nsAutoString result;
XPathGenerator::QuoteArgument(arg, result);
@ -39,10 +39,10 @@ TEST(TestXPathGenerator, TestQuoteArgumentWithSingleQuote)
TEST(TestXPathGenerator, TestQuoteArgumentWithDoubleQuote)
{
nsAutoString arg;
arg.Assign(NS_LITERAL_STRING("\"testing\""));
arg.AssignLiteral(u"\"testing\"");
nsAutoString expectedResult;
expectedResult.Assign(NS_LITERAL_STRING("\'\"testing\"\'"));
expectedResult.AssignLiteral(u"\'\"testing\"\'");
nsAutoString result;
XPathGenerator::QuoteArgument(arg, result);
@ -53,10 +53,10 @@ TEST(TestXPathGenerator, TestQuoteArgumentWithDoubleQuote)
TEST(TestXPathGenerator, TestQuoteArgumentWithSingleAndDoubleQuote)
{
nsAutoString arg;
arg.Assign(NS_LITERAL_STRING("\'testing\""));
arg.AssignLiteral(u"\'testing\"");
nsAutoString expectedResult;
expectedResult.Assign(NS_LITERAL_STRING("concat(\'\',\"\'\",\'testing\"\')"));
expectedResult.AssignLiteral(u"concat(\'\',\"\'\",\'testing\"\')");
nsAutoString result;
XPathGenerator::QuoteArgument(arg, result);
@ -68,10 +68,10 @@ TEST(TestXPathGenerator, TestQuoteArgumentWithSingleAndDoubleQuote)
TEST(TestXPathGenerator, TestQuoteArgumentWithDoubleQuoteAndASequenceOfSingleQuote)
{
nsAutoString arg;
arg.Assign(NS_LITERAL_STRING("\'\'\'\'testing\""));
arg.AssignLiteral(u"\'\'\'\'testing\"");
nsAutoString expectedResult;
expectedResult.Assign(NS_LITERAL_STRING("concat(\'\',\"\'\'\'\'\",\'testing\"\')"));
expectedResult.AssignLiteral(u"concat(\'\',\"\'\'\'\'\",\'testing\"\')");
nsAutoString result;
XPathGenerator::QuoteArgument(arg, result);
@ -83,10 +83,10 @@ TEST(TestXPathGenerator, TestQuoteArgumentWithDoubleQuoteAndASequenceOfSingleQuo
TEST(TestXPathGenerator, TestQuoteArgumentWithDoubleQuoteAndTwoSequencesOfSingleQuote)
{
nsAutoString arg;
arg.Assign(NS_LITERAL_STRING("\'\'\'\'testing\'\'\'\'\'\'\""));
arg.AssignLiteral(u"\'\'\'\'testing\'\'\'\'\'\'\"");
nsAutoString expectedResult;
expectedResult.Assign(NS_LITERAL_STRING("concat(\'\',\"\'\'\'\'\",\'testing\',\"\'\'\'\'\'\'\",\'\"\')"));
expectedResult.AssignLiteral(u"concat(\'\',\"\'\'\'\'\",\'testing\',\"\'\'\'\'\'\'\",\'\"\')");
nsAutoString result;
XPathGenerator::QuoteArgument(arg, result);
@ -98,10 +98,10 @@ TEST(TestXPathGenerator, TestQuoteArgumentWithDoubleQuoteAndTwoSequencesOfSingle
TEST(TestXPathGenerator, TestQuoteArgumentWithDoubleQuoteAndTwoSequencesOfSingleQuoteInMiddle)
{
nsAutoString arg;
arg.Assign(NS_LITERAL_STRING("t\'\'\'\'estin\'\'\'\'\'\'\"g"));
arg.AssignLiteral(u"t\'\'\'\'estin\'\'\'\'\'\'\"g");
nsAutoString expectedResult;
expectedResult.Assign(NS_LITERAL_STRING("concat(\'t\',\"\'\'\'\'\",\'estin\',\"\'\'\'\'\'\'\",\'\"g\')"));
expectedResult.AssignLiteral(u"concat(\'t\',\"\'\'\'\'\",\'estin\',\"\'\'\'\'\'\'\",\'\"g\')");
nsAutoString result;
XPathGenerator::QuoteArgument(arg, result);
@ -113,10 +113,10 @@ TEST(TestXPathGenerator, TestQuoteArgumentWithDoubleQuoteAndTwoSequencesOfSingle
TEST(TestXPathGenerator, TestEscapeNameWithNormalCharacters)
{
nsAutoString arg;
arg.Assign(NS_LITERAL_STRING("testing"));
arg.AssignLiteral(u"testing");
nsAutoString expectedResult;
expectedResult.Assign(NS_LITERAL_STRING("testing"));
expectedResult.AssignLiteral(u"testing");
nsAutoString result;
XPathGenerator::EscapeName(arg, result);
@ -127,10 +127,10 @@ TEST(TestXPathGenerator, TestEscapeNameWithNormalCharacters)
TEST(TestXPathGenerator, TestEscapeNameWithSpecialCharacters)
{
nsAutoString arg;
arg.Assign(NS_LITERAL_STRING("^testing!"));
arg.AssignLiteral(u"^testing!");
nsAutoString expectedResult;
expectedResult.Assign(NS_LITERAL_STRING("*[local-name()=\'^testing!\']"));
expectedResult.AssignLiteral(u"*[local-name()=\'^testing!\']");
nsAutoString result;
XPathGenerator::EscapeName(arg, result);

View File

@ -861,11 +861,11 @@ NS_IMETHODIMP
MediaDevice::GetMediaSource(nsAString& aMediaSource)
{
if (mMediaSource == MediaSourceEnum::Microphone) {
aMediaSource.Assign(NS_LITERAL_STRING("microphone"));
aMediaSource.AssignLiteral(u"microphone");
} else if (mMediaSource == MediaSourceEnum::AudioCapture) {
aMediaSource.Assign(NS_LITERAL_STRING("audioCapture"));
aMediaSource.AssignLiteral(u"audioCapture");
} else if (mMediaSource == MediaSourceEnum::Window) { // this will go away
aMediaSource.Assign(NS_LITERAL_STRING("window"));
aMediaSource.AssignLiteral(u"window");
} else { // all the rest are shared
aMediaSource.Assign(NS_ConvertUTF8toUTF16(
dom::MediaSourceEnumValues::strings[uint32_t(mMediaSource)].value));

View File

@ -88,7 +88,7 @@ AssembleClientData(const nsAString& aOrigin, const CryptoBuffer& aChallenge,
CollectedClientData clientDataObject;
clientDataObject.mChallenge.Assign(challengeBase64);
clientDataObject.mOrigin.Assign(aOrigin);
clientDataObject.mHashAlg.Assign(NS_LITERAL_STRING("SHA-256"));
clientDataObject.mHashAlg.AssignLiteral(u"SHA-256");
nsAutoString temp;
if (NS_WARN_IF(!clientDataObject.ToJSON(temp))) {

View File

@ -250,7 +250,7 @@ void nsMenuItemX::SetKeyEquiv()
keyChar.Assign(charCode);
}
else {
keyChar.Assign(NS_LITERAL_STRING(" "));
keyChar.AssignLiteral(u" ");
}
}