From 0d0c7559bff68b68849aa0166a55cb879053883c Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Thu, 16 Feb 2012 21:17:15 +0200 Subject: [PATCH] Optimize converter between QString and sha1_hash --- src/misc.h | 10 +++------- src/qtlibtorrent/qbtsession.cpp | 2 +- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/misc.h b/src/misc.h index 6bf26ac29..d837bc9e5 100644 --- a/src/misc.h +++ b/src/misc.h @@ -73,13 +73,9 @@ public: } static inline QString toQString(const libtorrent::sha1_hash &hash) { - std::ostringstream o; - o << hash; - return QString(o.str().c_str()); - } - - static inline libtorrent::sha1_hash toSha1Hash(const QString &hash) { - return libtorrent::sha1_hash(hash.toAscii().constData()); + char out[41]; + to_hex((char const*)&hash[0], libtorrent::sha1_hash::size, out); + return QString(out); } static void chmod644(const QDir& folder); diff --git a/src/qtlibtorrent/qbtsession.cpp b/src/qtlibtorrent/qbtsession.cpp index ab8e9bf50..68366a19b 100644 --- a/src/qtlibtorrent/qbtsession.cpp +++ b/src/qtlibtorrent/qbtsession.cpp @@ -909,7 +909,7 @@ QTorrentHandle QBtSession::addMagnetUri(QString magnet_uri, bool resumed) { Q_ASSERT(magnet_uri.startsWith("magnet:", Qt::CaseInsensitive)); // Check for duplicate torrent - if(s->find_torrent(misc::toSha1Hash(hash)).is_valid()) { + if(s->find_torrent(QStringToSha1(hash)).is_valid()) { qDebug("/!\\ Torrent is already in download list"); addConsoleMessage(tr("'%1' is already in download list.", "e.g: 'xxx.avi' is already in download list.").arg(magnet_uri)); return h;