[Pkg-owncloud-commits] [owncloud-client] 35/121: Checksum speedup. (#4968)
Sandro Knauß
hefee-guest at moszumanska.debian.org
Thu Jul 28 15:31:54 UTC 2016
This is an automated email from the git hooks/post-receive script.
hefee-guest pushed a commit to branch master
in repository owncloud-client.
commit b4900d60b76826d17de803ee0c727ac73f4492ba
Author: Olivier Goffart <olivier at woboq.com>
Date: Thu Jun 16 08:28:30 2016 +0200
Checksum speedup. (#4968)
No need to allocate (and initialize to 0) a 10 MiB buffer for each files, even
when most files are much smaller than that.
So make sure the buffer that we allocate is not bigger than the file size.
And Also 10 MiB is a bit big for a buffer. 500 KiB should be more than enough.
(Too big allocations can cause problem because of memory fragmentation and such)
---
src/libsync/filesystem.cpp | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/src/libsync/filesystem.cpp b/src/libsync/filesystem.cpp
index f5f5e7d..2dd6b51 100644
--- a/src/libsync/filesystem.cpp
+++ b/src/libsync/filesystem.cpp
@@ -496,16 +496,16 @@ QString FileSystem::fileSystemForPath(const QString & path)
}
#endif
-#define BUFSIZE 1024*1024*10
+#define BUFSIZE qint64(500*1024) // 500 KiB
static QByteArray readToCrypto( const QString& filename, QCryptographicHash::Algorithm algo )
{
- const qint64 bufSize = BUFSIZE;
- QByteArray buf(bufSize,0);
+ QFile file(filename);
+ const qint64 bufSize = qMin(BUFSIZE, file.size() + 1);
+ QByteArray buf(bufSize, Qt::Uninitialized);
QByteArray arr;
QCryptographicHash crypto( algo );
- QFile file(filename);
if (file.open(QIODevice::ReadOnly)) {
qint64 size;
while (!file.atEnd()) {
@@ -532,11 +532,11 @@ QByteArray FileSystem::calcSha1( const QString& filename )
#ifdef ZLIB_FOUND
QByteArray FileSystem::calcAdler32( const QString& filename )
{
- unsigned int adler = adler32(0L, Z_NULL, 0);
- const qint64 bufSize = BUFSIZE;
- QByteArray buf(bufSize, 0);
-
QFile file(filename);
+ const qint64 bufSize = qMin(BUFSIZE, file.size() + 1);
+ QByteArray buf(bufSize, Qt::Uninitialized);
+
+ unsigned int adler = adler32(0L, Z_NULL, 0);
if (file.open(QIODevice::ReadOnly)) {
qint64 size;
while (!file.atEnd()) {
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git
More information about the Pkg-owncloud-commits
mailing list