[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [baloo] src/engine: Databases: Use QByteArray::fromRawData when passing data to a codec
From:       Vishesh Handa <me () vhanda ! in>
Date:       2015-10-18 22:11:06
Message-ID: E1ZnwAU-0006AT-An () scm ! kde ! org
[Download RAW message or body]

Git commit c67546c4fc8c77d502895cdd240126542e105946 by Vishesh Handa.
Committed on 14/10/2015 at 23:13.
Pushed by vhanda into branch 'master'.

Databases: Use QByteArray::fromRawData when passing data to a codec

All 3 codecs seem to always copy the data on decoding. We can avoid the
extra copy over here by using QByteArray::fromRawData.

REVIEW: 125643

M  +1    -1    src/engine/documentdb.cpp
M  +1    -1    src/engine/positiondb.cpp
M  +1    -1    src/engine/postingdb.cpp

http://commits.kde.org/baloo/c67546c4fc8c77d502895cdd240126542e105946

diff --git a/src/engine/documentdb.cpp b/src/engine/documentdb.cpp
index 71c2f62..a739886 100644
--- a/src/engine/documentdb.cpp
+++ b/src/engine/documentdb.cpp
@@ -93,7 +93,7 @@ QVector<QByteArray> DocumentDB::get(quint64 docId)
     }
     Q_ASSERT_X(rc == 0, "DocumentDB::get", mdb_strerror(rc));
 
-    QByteArray arr(static_cast<char*>(val.mv_data), val.mv_size);
+    QByteArray arr = QByteArray::fromRawData(static_cast<char*>(val.mv_data), val.mv_size);
 
     DocTermsCodec codec;
     return codec.decode(arr);
diff --git a/src/engine/positiondb.cpp b/src/engine/positiondb.cpp
index 032192e..59ffe12 100644
--- a/src/engine/positiondb.cpp
+++ b/src/engine/positiondb.cpp
@@ -95,7 +95,7 @@ QVector<PositionInfo> PositionDB::get(const QByteArray& term)
     }
     Q_ASSERT_X(rc == 0, "PositionDB::get", mdb_strerror(rc));
 
-    QByteArray data(static_cast<char*>(val.mv_data), val.mv_size);
+    QByteArray data = QByteArray::fromRawData(static_cast<char*>(val.mv_data), val.mv_size);
 
     PositionCodec codec;
     return codec.decode(data);
diff --git a/src/engine/postingdb.cpp b/src/engine/postingdb.cpp
index 3045d42..92fa203 100644
--- a/src/engine/postingdb.cpp
+++ b/src/engine/postingdb.cpp
@@ -94,7 +94,7 @@ PostingList PostingDB::get(const QByteArray& term)
     }
     Q_ASSERT_X(rc == 0, "PostingDB::get", mdb_strerror(rc));
 
-    QByteArray arr(static_cast<char*>(val.mv_data), val.mv_size);
+    QByteArray arr = QByteArray::fromRawData(static_cast<char*>(val.mv_data), val.mv_size);
 
     PostingCodec codec;
     return codec.decode(arr);

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic