summaryrefslogtreecommitdiffstats
path: root/toolkit/components/url-classifier/nsCheckSummedOutputStream.cpp
diff options
context:
space:
mode:
authorThomas Nguyen <tnguyen@mozilla.com>2017-05-19 13:17:07 +0800
committerwolfbeast <mcwerewolf@gmail.com>2018-04-19 11:33:20 +0200
commit09bbda15b26b806c3d63ec5fa4a1f3431c18d96d (patch)
tree25990a4691873435231e0b731ae9543d47663404 /toolkit/components/url-classifier/nsCheckSummedOutputStream.cpp
parent0b5cb08596f57d5c56003734e6b35aca26e71fad (diff)
downloadUXP-09bbda15b26b806c3d63ec5fa4a1f3431c18d96d.tar
UXP-09bbda15b26b806c3d63ec5fa4a1f3431c18d96d.tar.gz
UXP-09bbda15b26b806c3d63ec5fa4a1f3431c18d96d.tar.lz
UXP-09bbda15b26b806c3d63ec5fa4a1f3431c18d96d.tar.xz
UXP-09bbda15b26b806c3d63ec5fa4a1f3431c18d96d.zip
Bug 1361699 - Add buffer when writing hashstore to file. r=gcp, r=mcmanus, a=RyanVM
We write a lot of 4-bytes prefixes to file which call many system calls. We should use a buffer and only write to file if the buffer is full or finish writing. nsIBufferedOutputStream is a good candidate to do that MozReview-Commit-ID: CzGOd7iXVTv --HG-- extra : source : 8f2b4efc5f0d3191a7e80d9324933621e111b44a
Diffstat (limited to 'toolkit/components/url-classifier/nsCheckSummedOutputStream.cpp')
-rw-r--r--toolkit/components/url-classifier/nsCheckSummedOutputStream.cpp17
1 files changed, 7 insertions, 10 deletions
diff --git a/toolkit/components/url-classifier/nsCheckSummedOutputStream.cpp b/toolkit/components/url-classifier/nsCheckSummedOutputStream.cpp
index 68f9f1f6f..0e89fd20c 100644
--- a/toolkit/components/url-classifier/nsCheckSummedOutputStream.cpp
+++ b/toolkit/components/url-classifier/nsCheckSummedOutputStream.cpp
@@ -13,14 +13,11 @@
// nsCheckSummedOutputStream
NS_IMPL_ISUPPORTS_INHERITED(nsCheckSummedOutputStream,
- nsSafeFileOutputStream,
- nsISafeOutputStream,
- nsIOutputStream,
- nsIFileOutputStream)
+ nsBufferedOutputStream,
+ nsISafeOutputStream)
NS_IMETHODIMP
-nsCheckSummedOutputStream::Init(nsIFile* file, int32_t ioFlags, int32_t perm,
- int32_t behaviorFlags)
+nsCheckSummedOutputStream::Init(nsIOutputStream* stream, uint32_t bufferSize)
{
nsresult rv;
mHash = do_CreateInstance(NS_CRYPTO_HASH_CONTRACTID, &rv);
@@ -29,7 +26,7 @@ nsCheckSummedOutputStream::Init(nsIFile* file, int32_t ioFlags, int32_t perm,
rv = mHash->Init(nsICryptoHash::MD5);
NS_ENSURE_SUCCESS(rv, rv);
- return nsSafeFileOutputStream::Init(file, ioFlags, perm, behaviorFlags);
+ return nsBufferedOutputStream::Init(stream, bufferSize);
}
NS_IMETHODIMP
@@ -39,12 +36,12 @@ nsCheckSummedOutputStream::Finish()
NS_ENSURE_SUCCESS(rv, rv);
uint32_t written;
- rv = nsSafeFileOutputStream::Write(reinterpret_cast<const char*>(mCheckSum.BeginReading()),
+ rv = nsBufferedOutputStream::Write(reinterpret_cast<const char*>(mCheckSum.BeginReading()),
mCheckSum.Length(), &written);
NS_ASSERTION(written == mCheckSum.Length(), "Error writing stream checksum");
NS_ENSURE_SUCCESS(rv, rv);
- return nsSafeFileOutputStream::Finish();
+ return nsBufferedOutputStream::Finish();
}
NS_IMETHODIMP
@@ -53,7 +50,7 @@ nsCheckSummedOutputStream::Write(const char *buf, uint32_t count, uint32_t *resu
nsresult rv = mHash->Update(reinterpret_cast<const uint8_t*>(buf), count);
NS_ENSURE_SUCCESS(rv, rv);
- return nsSafeFileOutputStream::Write(buf, count, result);
+ return nsBufferedOutputStream::Write(buf, count, result);
}
////////////////////////////////////////////////////////////////////////////////