Bug 1453134 - part 3 - be smarter about input stream semantics in DataTransfer; r=baku

We could have used the new NS_NewCStringInputStream overload here, but
it seemed nicer to directly transfer ownership into the newly-created
stream.  If we're going to be more efficient here, we might as well go
as far as when can without making the code too ugly.
This commit is contained in:
Nathan Froyd 2018-04-11 10:06:17 -04:00
Родитель 62f2c5af64
Коммит 798efd6d66
1 изменённых файлов: 7 добавлений и 3 удалений

Просмотреть файл

@ -6,6 +6,7 @@
#include "mozilla/ArrayUtils.h"
#include "mozilla/BasicEvents.h"
#include "mozilla/CheckedInt.h"
#include "DataTransfer.h"
@ -1470,11 +1471,14 @@ DataTransfer::FillInExternalCustomTypes(nsIVariant* aData, uint32_t aIndex,
return;
}
nsAutoCString str;
str.Adopt(chrs, len);
CheckedInt<int32_t> checkedLen(len);
if (!checkedLen.isValid()) {
return;
}
nsCOMPtr<nsIInputStream> stringStream;
NS_NewCStringInputStream(getter_AddRefs(stringStream), str);
NS_NewByteInputStream(getter_AddRefs(stringStream), chrs, checkedLen.value(),
NS_ASSIGNMENT_ADOPT);
nsCOMPtr<nsIObjectInputStream> stream =
NS_NewObjectInputStream(stringStream);