Change in kio[master]: Change how UDSEntry load and save parsing is handled.

Mark Gaiser (Code Review) noreply at kde.org
Mon Feb 2 18:53:58 UTC 2015


Mark Gaiser has uploaded a new change for review.

  https://gerrit.vesnicky.cesnet.cz/r/352

Change subject: Change how UDSEntry load and save parsing is handled.
......................................................................

Change how UDSEntry load and save parsing is handled.

This isn't faster or slower then before (benchmarks showed that it's about equally in speed as before).
This patch is preperation work for more optimizations in SlaveBase. That will write directly in a buffer
using similar methods as UDSEntry does now. UDSEntry is changed to be consistent with that approach.

CHANGELOG: Change how UDSEntry load and save parsing is handled
Change-Id: I50af82e17f9fdd73e77d9e98411cf54fada2a962
---
M autotests/udsentrytest.cpp
M src/core/udsentry.cpp
2 files changed, 31 insertions(+), 17 deletions(-)


  git pull ssh://gerrit.vesnicky.cesnet.cz:29418/kio refs/changes/52/352/1

diff --git a/autotests/udsentrytest.cpp b/autotests/udsentrytest.cpp
index 04e072e..066fd86 100644
--- a/autotests/udsentrytest.cpp
+++ b/autotests/udsentrytest.cpp
@@ -183,17 +183,21 @@
     {
         QDataStream stream(&data, QIODevice::WriteOnly);
         foreach (const QVector<UDSTestField> &testCase, testCases) {
-            stream << testCase.count();
+            const int size = testCase.count();
+            stream.writeRawData(reinterpret_cast<const char*>(&size), sizeof(int));
 
             foreach (const UDSTestField &field, testCase) {
                 uint uds = field.m_uds;
-                stream << uds;
+                stream.writeRawData(reinterpret_cast<const char*>(&uds), sizeof(uint));
 
                 if (uds & KIO::UDSEntry::UDS_STRING) {
-                    stream << field.m_string;
+                    const QString &str = field.m_string;
+                    int size = str.size();
+                    stream.writeRawData(reinterpret_cast<const char*>(&size), sizeof(int));
+                    stream.writeRawData(reinterpret_cast<const char*>(str.utf16()), sizeof(ushort) * size);
                 } else {
                     Q_ASSERT(uds & KIO::UDSEntry::UDS_NUMBER);
-                    stream << field.m_long;
+                    stream.writeRawData(reinterpret_cast<const char*>(&field.m_long), sizeof(long long));
                 }
             }
         }
diff --git a/src/core/udsentry.cpp b/src/core/udsentry.cpp
index 38e40c5..d92b3fd 100644
--- a/src/core/udsentry.cpp
+++ b/src/core/udsentry.cpp
@@ -188,16 +188,19 @@
     const QVector<Field> &fields = a.d->fields;
     const int size = udsIndexes.size();
 
-    s << size;
+    s.writeRawData(reinterpret_cast<const char*>(&size), sizeof(int));
 
     for (int index = 0; index < size; ++index) {
         uint uds = udsIndexes.at(index);
-        s << uds;
+        s.writeRawData(reinterpret_cast<const char*>(&uds), sizeof(uint));
 
         if (uds & KIO::UDSEntry::UDS_STRING) {
-            s << fields.at(index).m_str;
+            const QString &str = fields.at(index).m_str;
+            int size = str.size();
+            s.writeRawData(reinterpret_cast<const char*>(&size), sizeof(int));
+            s.writeRawData(reinterpret_cast<const char*>(str.utf16()), sizeof(ushort) * size);
         } else if (uds & KIO::UDSEntry::UDS_NUMBER) {
-            s << fields.at(index).m_long;
+            s.writeRawData(reinterpret_cast<const char*>(&fields.at(index).m_long), sizeof(long long));
         } else {
             Q_ASSERT_X(false, "KIO::UDSEntry", "Found a field with an invalid type");
         }
@@ -211,8 +214,9 @@
     QVector<Field> &fields = a.d->fields;
     QVector<uint> &udsIndexes = a.d->udsIndexes;
 
-    quint32 size;
-    s >> size;
+    int size;
+    s.readRawData(reinterpret_cast<char*>(&size), sizeof(int));
+
     fields.reserve(size);
     udsIndexes.reserve(size);
 
@@ -220,21 +224,27 @@
     // will often be the same for many entries in a row. Caching them
     // permits to use implicit sharing to save memory.
     static QVector<QString> cachedStrings;
-    if (quint32(cachedStrings.size()) < size) {
+    if (int(cachedStrings.size()) < size) {
         cachedStrings.resize(size);
     }
 
-    for (quint32 i = 0; i < size; ++i) {
-        quint32 uds;
-        s >> uds;
+    for (int i = 0; i < size; ++i) {
+        uint uds;
+        s.readRawData(reinterpret_cast<char*>(&uds), sizeof(uint));
+
         udsIndexes.append(uds);
 
         if (uds & KIO::UDSEntry::UDS_STRING) {
             // If the QString is the same like the one we read for the
             // previous UDSEntry at the i-th position, use an implicitly
             // shared copy of the same QString to save memory.
-            QString buffer;
-            s >> buffer;
+            int length;
+            s.readRawData(reinterpret_cast<char*>(&length), sizeof(int));
+
+            char tempBuffer[length * sizeof(ushort)];
+            s.readRawData(tempBuffer, length * sizeof(ushort));
+
+            QString buffer = QString::fromUtf16(reinterpret_cast<const ushort*>(tempBuffer), length);
 
             if (buffer != cachedStrings.at(i)) {
                 cachedStrings[i] = buffer;
@@ -243,7 +253,7 @@
             fields.append(Field(cachedStrings.at(i)));
         } else if (uds & KIO::UDSEntry::UDS_NUMBER) {
             long long value;
-            s >> value;
+            s.readRawData(reinterpret_cast<char*>(&value), sizeof(long long));
             fields.append(Field(value));
         } else {
             Q_ASSERT_X(false, "KIO::UDSEntry", "Found a field with an invalid type");

-- 
To view, visit https://gerrit.vesnicky.cesnet.cz/r/352
To unsubscribe, visit https://gerrit.vesnicky.cesnet.cz/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I50af82e17f9fdd73e77d9e98411cf54fada2a962
Gerrit-PatchSet: 1
Gerrit-Project: kio
Gerrit-Branch: master
Gerrit-Owner: Mark Gaiser <markg85 at gmail.com>
Gerrit-Reviewer: David Faure <faure at kde.org>
Gerrit-Reviewer: Frank Reininghaus <frank78ac at googlemail.com>
Gerrit-Reviewer: Sysadmin Testing Account <null at kde.org>


More information about the Kde-frameworks-devel mailing list