mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-09 09:18:42 +09:00
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
This commit is contained in:
parent
629a9a0f91
commit
787c782fd8
4 changed files with 26 additions and 26 deletions
|
|
@ -12,25 +12,27 @@
|
|||
#include "nsICryptoHash.h"
|
||||
#include "nsNetCID.h"
|
||||
#include "nsString.h"
|
||||
#include "../../../netwerk/base/nsFileStreams.h"
|
||||
#include "nsToolkitCompsCID.h"
|
||||
#include "../../../netwerk/base/nsBufferedStreams.h"
|
||||
#include "prio.h"
|
||||
|
||||
class nsCheckSummedOutputStream : public nsSafeFileOutputStream
|
||||
class nsCheckSummedOutputStream : public nsBufferedOutputStream
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
// Size of MD5 hash in bytes
|
||||
static const uint32_t CHECKSUM_SIZE = 16;
|
||||
static const uint32_t MAX_BUFFER_SIZE = 64 * 1024;
|
||||
|
||||
nsCheckSummedOutputStream() {}
|
||||
|
||||
NS_IMETHOD Finish() override;
|
||||
NS_IMETHOD Write(const char *buf, uint32_t count, uint32_t *result) override;
|
||||
NS_IMETHOD Init(nsIFile* file, int32_t ioFlags, int32_t perm, int32_t behaviorFlags) override;
|
||||
NS_IMETHOD Init(nsIOutputStream* stream, uint32_t bufferSize) override;
|
||||
|
||||
protected:
|
||||
virtual ~nsCheckSummedOutputStream() { nsSafeFileOutputStream::Close(); }
|
||||
virtual ~nsCheckSummedOutputStream() { nsBufferedOutputStream::Close(); }
|
||||
|
||||
nsCOMPtr<nsICryptoHash> mHash;
|
||||
nsCString mCheckSum;
|
||||
|
|
@ -39,13 +41,15 @@ protected:
|
|||
// returns a file output stream which can be QI'ed to nsIFileOutputStream.
|
||||
inline nsresult
|
||||
NS_NewCheckSummedOutputStream(nsIOutputStream **result,
|
||||
nsIFile *file,
|
||||
int32_t ioFlags = -1,
|
||||
int32_t perm = -1,
|
||||
int32_t behaviorFlags = 0)
|
||||
nsIFile *file)
|
||||
{
|
||||
nsCOMPtr<nsIFileOutputStream> out = new nsCheckSummedOutputStream();
|
||||
nsresult rv = out->Init(file, ioFlags, perm, behaviorFlags);
|
||||
nsCOMPtr<nsIOutputStream> localOutFile;
|
||||
nsresult rv = NS_NewSafeLocalFileOutputStream(getter_AddRefs(localOutFile), file,
|
||||
PR_WRONLY | PR_TRUNCATE | PR_CREATE_FILE);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIBufferedOutputStream> out = new nsCheckSummedOutputStream();
|
||||
rv = out->Init(localOutFile, nsCheckSummedOutputStream::CHECKSUM_SIZE);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
out.forget(result);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue