From: Olivier Goffart Date: Tue, 6 Nov 2018 10:46:01 +0000 (+0100) Subject: PropagateUpload: Avoid many allocations by using QByteArrayLiteral X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~12^2~21^2~468^2~423 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=1783db58119c1ce3f6122750b7e211933e189482;p=nextcloud-desktop.git PropagateUpload: Avoid many allocations by using QByteArrayLiteral --- diff --git a/src/libsync/propagateupload.cpp b/src/libsync/propagateupload.cpp index 7211f4fba..ac83b5c9f 100644 --- a/src/libsync/propagateupload.cpp +++ b/src/libsync/propagateupload.cpp @@ -705,11 +705,11 @@ void PropagateUploadFileCommon::abortWithError(SyncFileItem::Status status, cons QMap PropagateUploadFileCommon::headers() { QMap headers; - headers["OC-Async"] = "1"; - headers["Content-Type"] = "application/octet-stream"; - headers["X-OC-Mtime"] = QByteArray::number(qint64(_item->_modtime)); + headers[QByteArrayLiteral("OC-Async")] = QByteArrayLiteral("1"); + headers[QByteArrayLiteral("Content-Type")] = QByteArrayLiteral("application/octet-stream"); + headers[QByteArrayLiteral("X-OC-Mtime")] = QByteArray::number(qint64(_item->_modtime)); - if (_item->_file.contains(".sys.admin#recall#")) { + if (_item->_file.contains(QLatin1String(".sys.admin#recall#"))) { // This is a file recall triggered by the admin. Note: the // recall list file created by the admin and downloaded by the // client (.sys.admin#recall#) also falls into this category @@ -726,21 +726,21 @@ QMap PropagateUploadFileCommon::headers() && !_deleteExisting) { // We add quotes because the owncloud server always adds quotes around the etag, and // csync_owncloud.c's owncloud_file_id always strips the quotes. - headers["If-Match"] = '"' + _item->_etag + '"'; + headers[QByteArrayLiteral("If-Match")] = '"' + _item->_etag + '"'; } // Set up a conflict file header pointing to the original file auto conflictRecord = propagator()->_journal->conflictRecord(_item->_file.toUtf8()); if (conflictRecord.isValid()) { - headers["OC-Conflict"] = "1"; + headers[QByteArrayLiteral("OC-Conflict")] = "1"; if (!conflictRecord.initialBasePath.isEmpty()) - headers["OC-ConflictInitialBasePath"] = conflictRecord.initialBasePath; + headers[QByteArrayLiteral("OC-ConflictInitialBasePath")] = conflictRecord.initialBasePath; if (!conflictRecord.baseFileId.isEmpty()) - headers["OC-ConflictBaseFileId"] = conflictRecord.baseFileId; + headers[QByteArrayLiteral("OC-ConflictBaseFileId")] = conflictRecord.baseFileId; if (conflictRecord.baseModtime != -1) - headers["OC-ConflictBaseMtime"] = QByteArray::number(conflictRecord.baseModtime); + headers[QByteArrayLiteral("OC-ConflictBaseMtime")] = QByteArray::number(conflictRecord.baseModtime); if (!conflictRecord.baseEtag.isEmpty()) - headers["OC-ConflictBaseEtag"] = conflictRecord.baseEtag; + headers[QByteArrayLiteral("OC-ConflictBaseEtag")] = conflictRecord.baseEtag; } if (_uploadEncryptedHelper && !_uploadEncryptedHelper->_folderToken.isEmpty()) { diff --git a/src/libsync/propagateuploadng.cpp b/src/libsync/propagateuploadng.cpp index 7732af3a6..336b02a1f 100644 --- a/src/libsync/propagateuploadng.cpp +++ b/src/libsync/propagateuploadng.cpp @@ -295,15 +295,15 @@ void PropagateUploadFileNG::startNextChunk() auto headers = PropagateUploadFileCommon::headers(); // "If-Match applies to the source, but we are interested in comparing the etag of the destination - auto ifMatch = headers.take("If-Match"); + auto ifMatch = headers.take(QByteArrayLiteral("If-Match")); if (!ifMatch.isEmpty()) { - headers["If"] = "<" + QUrl::toPercentEncoding(destination, "/") + "> ([" + ifMatch + "])"; + headers[QByteArrayLiteral("If")] = "<" + QUrl::toPercentEncoding(destination, "/") + "> ([" + ifMatch + "])"; } if (!_transmissionChecksumHeader.isEmpty()) { qCInfo(lcPropagateUpload) << destination << _transmissionChecksumHeader; headers[checkSumHeaderC] = _transmissionChecksumHeader; } - headers["OC-Total-Length"] = QByteArray::number(fileSize); + headers[QByteArrayLiteral("OC-Total-Length")] = QByteArray::number(fileSize); auto job = new MoveJob(propagator()->account(), Utility::concatUrlPath(chunkUrl(), "/.file"), destination, headers, this); diff --git a/src/libsync/propagateuploadv1.cpp b/src/libsync/propagateuploadv1.cpp index c305d8f32..0f282a356 100644 --- a/src/libsync/propagateuploadv1.cpp +++ b/src/libsync/propagateuploadv1.cpp @@ -85,8 +85,8 @@ void PropagateUploadFileV1::startNextChunk() } quint64 fileSize = _fileToUpload._size; auto headers = PropagateUploadFileCommon::headers(); - headers["OC-Total-Length"] = QByteArray::number(fileSize); - headers["OC-Chunk-Size"] = QByteArray::number(quint64(chunkSize())); + headers[QByteArrayLiteral("OC-Total-Length")] = QByteArray::number(fileSize); + headers[QByteArrayLiteral("OC-Chunk-Size")] = QByteArray::number(quint64(chunkSize())); QString path = _fileToUpload._file; @@ -101,7 +101,7 @@ void PropagateUploadFileV1::startNextChunk() qCInfo(lcPropagateUpload) << "Upload chunk" << sendingChunk << "of" << _chunkCount << "transferid(remote)=" << transid; path += QString("-chunking-%1-%2-%3").arg(transid).arg(_chunkCount).arg(sendingChunk); - headers["OC-Chunked"] = "1"; + headers[QByteArrayLiteral("OC-Chunked")] = QByteArrayLiteral("1"); chunkStart = chunkSize() * quint64(sendingChunk); currentChunkSize = chunkSize();