Bug 1453134 - part 2 - use new string input stream constructor in FSURLEncoded; r=baku

The XXX comment here wants to give up the string data when we create the
outgoing stream.  Giving up the string data is legitimate, because
GetEncodedSubmission is the last operation to be called on this object;
mQueryString is effectively dead after this function returns.
Accordingly, we can Move() mQueryString into the outgoing stream for a
nice efficiency boost.
This commit is contained in:
Nathan Froyd
2018-04-11 10:06:17 -04:00
parent 0018264d57
commit 75c1042689

View File

@@ -302,13 +302,11 @@ FSURLEncoded::GetEncodedSubmission(nsIURI* aURI,
.SetPathQueryRef(path)
.Finalize(aOutURI);
} else {
uint32_t queryStringLength = mQueryString.Length();
nsCOMPtr<nsIInputStream> dataStream;
// XXX We *really* need to either get the string to disown its data (and
// not destroy it), or make a string input stream that owns the CString
// that is passed to it. Right now this operation does a copy.
rv = NS_NewCStringInputStream(getter_AddRefs(dataStream), mQueryString);
rv = NS_NewCStringInputStream(getter_AddRefs(dataStream), Move(mQueryString));
NS_ENSURE_SUCCESS(rv, rv);
mQueryString.Truncate();
nsCOMPtr<nsIMIMEInputStream> mimeStream(
do_CreateInstance("@mozilla.org/network/mime-input-stream;1", &rv));
@@ -318,10 +316,9 @@ FSURLEncoded::GetEncodedSubmission(nsIURI* aURI,
"application/x-www-form-urlencoded");
mimeStream->SetData(dataStream);
*aPostDataStream = mimeStream;
NS_ADDREF(*aPostDataStream);
mimeStream.forget(aPostDataStream);
*aPostDataStreamLength = mQueryString.Length();
*aPostDataStreamLength = queryStringLength;
}
} else {