From edbc3f8fdeb4365b36f1edef2c32eac37e7b23f6 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 8 Aug 2017 20:25:10 +0200 Subject: [PATCH] Use QDataStream directly on QByteArray. --- Telegram/SourceFiles/auth_session.cpp | 14 ++------------ Telegram/SourceFiles/autoupdater.cpp | 4 +--- Telegram/SourceFiles/codegen/style/generator.cpp | 5 +---- Telegram/SourceFiles/mtproto/dc_options.cpp | 16 ++-------------- .../SourceFiles/ui/style/style_core_icon.cpp | 5 +---- Telegram/SourceFiles/ui/widgets/input_fields.cpp | 9 ++------- 6 files changed, 9 insertions(+), 44 deletions(-) diff --git a/Telegram/SourceFiles/auth_session.cpp b/Telegram/SourceFiles/auth_session.cpp index 044a604167..1834f27edd 100644 --- a/Telegram/SourceFiles/auth_session.cpp +++ b/Telegram/SourceFiles/auth_session.cpp @@ -54,12 +54,7 @@ QByteArray AuthSessionData::serialize() const { auto result = QByteArray(); result.reserve(size); { - QBuffer buffer(&result); - if (!buffer.open(QIODevice::WriteOnly)) { - Unexpected("Can't open data for AuthSessionData::serialize()"); - } - - QDataStream stream(&buffer); + QDataStream stream(&result, QIODevice::WriteOnly); stream.setVersion(QDataStream::Qt_5_1); stream << static_cast(_variables.selectorTab); stream << qint32(_variables.lastSeenWarningSeen ? 1 : 0); @@ -84,12 +79,7 @@ void AuthSessionData::constructFromSerialized(const QByteArray &serialized) { return; } - auto readonly = serialized; - QBuffer buffer(&readonly); - if (!buffer.open(QIODevice::ReadOnly)) { - Unexpected("Can't open data for DcOptions::constructFromSerialized()"); - } - QDataStream stream(&buffer); + QDataStream stream(serialized); stream.setVersion(QDataStream::Qt_5_1); qint32 selectorTab = static_cast(ChatHelpers::SelectorTab::Emoji); qint32 lastSeenWarningSeen = 0; diff --git a/Telegram/SourceFiles/autoupdater.cpp b/Telegram/SourceFiles/autoupdater.cpp index 5dcda0fb43..1fdd261f85 100644 --- a/Telegram/SourceFiles/autoupdater.cpp +++ b/Telegram/SourceFiles/autoupdater.cpp @@ -362,9 +362,7 @@ void UpdateChecker::unpackUpdate() { quint32 version; { - QBuffer buffer(&uncompressed); - buffer.open(QIODevice::ReadOnly); - QDataStream stream(&buffer); + QDataStream stream(uncompressed); stream.setVersion(QDataStream::Qt_5_1); stream >> version; diff --git a/Telegram/SourceFiles/codegen/style/generator.cpp b/Telegram/SourceFiles/codegen/style/generator.cpp index 131a8dc2fe..0ecc586a35 100644 --- a/Telegram/SourceFiles/codegen/style/generator.cpp +++ b/Telegram/SourceFiles/codegen/style/generator.cpp @@ -1176,10 +1176,7 @@ QByteArray iconMaskValueSize(int width, int height) { QLatin1String sizeTag("SIZE:"); result.append(sizeTag.data(), sizeTag.size()); { - QBuffer buffer(&result); - buffer.open(QIODevice::Append); - - QDataStream stream(&buffer); + QDataStream stream(&result, QIODevice::Append); stream.setVersion(QDataStream::Qt_5_1); stream << qint32(width) << qint32(height); } diff --git a/Telegram/SourceFiles/mtproto/dc_options.cpp b/Telegram/SourceFiles/mtproto/dc_options.cpp index 059fcfcb68..bf293cfff3 100644 --- a/Telegram/SourceFiles/mtproto/dc_options.cpp +++ b/Telegram/SourceFiles/mtproto/dc_options.cpp @@ -247,13 +247,7 @@ QByteArray DcOptions::serialize() const { auto result = QByteArray(); result.reserve(size); { - QBuffer buffer(&result); - if (!buffer.open(QIODevice::WriteOnly)) { - LOG(("MTP Error: Can't open data for DcOptions::serialize()")); - return result; - } - - QDataStream stream(&buffer); + QDataStream stream(&result, QIODevice::WriteOnly); stream.setVersion(QDataStream::Qt_5_1); stream << qint32(_data.size()); for (auto &item : _data) { @@ -273,13 +267,7 @@ QByteArray DcOptions::serialize() const { } void DcOptions::constructFromSerialized(const QByteArray &serialized) { - auto readonly = serialized; - QBuffer buffer(&readonly); - if (!buffer.open(QIODevice::ReadOnly)) { - LOG(("MTP Error: Can't open data for DcOptions::constructFromSerialized()")); - return; - } - QDataStream stream(&buffer); + QDataStream stream(serialized); stream.setVersion(QDataStream::Qt_5_1); auto count = qint32(0); stream >> count; diff --git a/Telegram/SourceFiles/ui/style/style_core_icon.cpp b/Telegram/SourceFiles/ui/style/style_core_icon.cpp index fa90d5ca72..c3eedc5849 100644 --- a/Telegram/SourceFiles/ui/style/style_core_icon.cpp +++ b/Telegram/SourceFiles/ui/style/style_core_icon.cpp @@ -84,10 +84,7 @@ QSize readGeneratedSize(const IconMask *mask, DBIScale scale) { size -= sizeTag.size(); data += sizeTag.size(); auto baForStream = QByteArray::fromRawData(reinterpret_cast(data), size); - QBuffer buffer(&baForStream); - buffer.open(QIODevice::ReadOnly); - - QDataStream stream(&buffer); + QDataStream stream(baForStream); stream.setVersion(QDataStream::Qt_5_1); qint32 width = 0, height = 0; diff --git a/Telegram/SourceFiles/ui/widgets/input_fields.cpp b/Telegram/SourceFiles/ui/widgets/input_fields.cpp index a1cd85ce23..9e9bf9338e 100644 --- a/Telegram/SourceFiles/ui/widgets/input_fields.cpp +++ b/Telegram/SourceFiles/ui/widgets/input_fields.cpp @@ -81,9 +81,7 @@ QByteArray FlatTextarea::serializeTagsList(const TagList &tags) { QByteArray tagsSerialized; { - QBuffer buffer(&tagsSerialized); - buffer.open(QIODevice::WriteOnly); - QDataStream stream(&buffer); + QDataStream stream(&tagsSerialized, QIODevice::WriteOnly); stream.setVersion(QDataStream::Qt_5_1); stream << qint32(tags.size()); for_const (auto &tag, tags) { @@ -99,10 +97,7 @@ FlatTextarea::TagList FlatTextarea::deserializeTagsList(QByteArray data, int tex return result; } - QBuffer buffer(&data); - buffer.open(QIODevice::ReadOnly); - - QDataStream stream(&buffer); + QDataStream stream(data); stream.setVersion(QDataStream::Qt_5_1); qint32 tagCount = 0;