From de5f38a160372811c36718b7e02b3d7d94ff5c73 Mon Sep 17 00:00:00 2001 From: Ivan Sorokin Date: Sat, 18 Oct 2014 03:42:36 +0400 Subject: [PATCH] Speedup compilation speed libtorrent has a relatively heavy headers, that take lots of time to process. This commit removes unnecessary includes of libtorrent headers and replaces them with forward declarations. I had to move some functions in QBtSession from slots to regular functions because moc'ed file want to see complete types of all parameters of slots. "time make" of full rebuild before this series of commits: real 13m35.937s user 12m1.295s sys 1m25.908s after: real 10m54.390s user 9m31.167s sys 1m12.580s --- src/fs_utils.h | 1 - src/preferences/options_imp.h | 1 - src/properties/peeraddition.h | 3 +- src/qtlibtorrent/qbtsession.cpp | 97 ++++++++++++++++--------------- src/qtlibtorrent/qbtsession.h | 49 +++++++++++++--- src/qtlibtorrent/qtorrenthandle.h | 2 - src/qtlibtorrent/torrentmodel.cpp | 2 + src/statsdialog.cpp | 2 + src/statusbar.h | 3 + src/webui/btjson.cpp | 2 + src/webui/httpconnection.cpp | 2 + 11 files changed, 105 insertions(+), 59 deletions(-) diff --git a/src/fs_utils.h b/src/fs_utils.h index be7f6ba21..eeceec516 100644 --- a/src/fs_utils.h +++ b/src/fs_utils.h @@ -32,7 +32,6 @@ #define FS_UTILS_H #include -#include /** * Utility functions related to file system. diff --git a/src/preferences/options_imp.h b/src/preferences/options_imp.h index f219239d8..4dbf277a5 100755 --- a/src/preferences/options_imp.h +++ b/src/preferences/options_imp.h @@ -32,7 +32,6 @@ #define OPTIONS_IMP_H #include "ui_options.h" -#include // actions on double-click on torrents enum DoubleClickAction {TOGGLE_PAUSE, OPEN_DEST, NO_ACTION}; diff --git a/src/properties/peeraddition.h b/src/properties/peeraddition.h index 07cde7994..b4f778f40 100644 --- a/src/properties/peeraddition.h +++ b/src/properties/peeraddition.h @@ -37,7 +37,8 @@ #include #include "ui_peer.h" -#include +#include +#include #include #if BOOST_VERSION < 103500 diff --git a/src/qtlibtorrent/qbtsession.cpp b/src/qtlibtorrent/qbtsession.cpp index 50b4b6edc..3795c67d4 100755 --- a/src/qtlibtorrent/qbtsession.cpp +++ b/src/qtlibtorrent/qbtsession.cpp @@ -70,6 +70,9 @@ #include #include #include +#include +#include +#include #include #include #include "dnsupdater.h" @@ -2056,48 +2059,6 @@ void QBtSession::disableIPFilter() { filterPath = ""; } -// Set BT session settings (user_agent) -void QBtSession::setSessionSettings(const session_settings &sessionSettings) { - qDebug("Set session settings"); - s->set_settings(sessionSettings); -} - -// Set Proxy -void QBtSession::setProxySettings(proxy_settings proxySettings) { - qDebug() << Q_FUNC_INFO; - - proxySettings.proxy_peer_connections = Preferences::instance()->proxyPeerConnections(); - s->set_proxy(proxySettings); - - // Define environment variable - QString proxy_str; - switch(proxySettings.type) { - case proxy_settings::http_pw: - proxy_str = "http://"+misc::toQString(proxySettings.username)+":"+misc::toQString(proxySettings.password)+"@"+misc::toQString(proxySettings.hostname)+":"+QString::number(proxySettings.port); - break; - case proxy_settings::http: - proxy_str = "http://"+misc::toQString(proxySettings.hostname)+":"+QString::number(proxySettings.port); - break; - case proxy_settings::socks5: - proxy_str = misc::toQString(proxySettings.hostname)+":"+QString::number(proxySettings.port); - break; - case proxy_settings::socks5_pw: - proxy_str = misc::toQString(proxySettings.username)+":"+misc::toQString(proxySettings.password)+"@"+misc::toQString(proxySettings.hostname)+":"+QString::number(proxySettings.port); - break; - default: - qDebug("Disabling HTTP communications proxy"); - qputenv("http_proxy", QByteArray()); - qputenv("sock_proxy", QByteArray()); - return; - } - // We need this for urllib in search engine plugins - qDebug("HTTP communications proxy string: %s", qPrintable(proxy_str)); - if (proxySettings.type == proxy_settings::socks5 || proxySettings.type == proxy_settings::socks5_pw) - qputenv("sock_proxy", proxy_str.toLocal8Bit()); - else - qputenv("http_proxy", proxy_str.toLocal8Bit()); -} - void QBtSession::recursiveTorrentDownload(const QTorrentHandle &h) { try { for (int i=0; istatus(); } +void QBtSession::applyEncryptionSettings(pe_settings se) { + qDebug("Applying encryption settings"); + s->set_pe_settings(se); +} + +// Set Proxy +void QBtSession::setProxySettings(proxy_settings proxySettings) { + qDebug() << Q_FUNC_INFO; + + proxySettings.proxy_peer_connections = Preferences::instance()->proxyPeerConnections(); + s->set_proxy(proxySettings); + + // Define environment variable + QString proxy_str; + switch(proxySettings.type) { + case proxy_settings::http_pw: + proxy_str = "http://"+misc::toQString(proxySettings.username)+":"+misc::toQString(proxySettings.password)+"@"+misc::toQString(proxySettings.hostname)+":"+QString::number(proxySettings.port); + break; + case proxy_settings::http: + proxy_str = "http://"+misc::toQString(proxySettings.hostname)+":"+QString::number(proxySettings.port); + break; + case proxy_settings::socks5: + proxy_str = misc::toQString(proxySettings.hostname)+":"+QString::number(proxySettings.port); + break; + case proxy_settings::socks5_pw: + proxy_str = misc::toQString(proxySettings.username)+":"+misc::toQString(proxySettings.password)+"@"+misc::toQString(proxySettings.hostname)+":"+QString::number(proxySettings.port); + break; + default: + qDebug("Disabling HTTP communications proxy"); + qputenv("http_proxy", QByteArray()); + qputenv("sock_proxy", QByteArray()); + return; + } + // We need this for urllib in search engine plugins + qDebug("HTTP communications proxy string: %s", qPrintable(proxy_str)); + if (proxySettings.type == proxy_settings::socks5 || proxySettings.type == proxy_settings::socks5_pw) + qputenv("sock_proxy", proxy_str.toLocal8Bit()); + else + qputenv("http_proxy", proxy_str.toLocal8Bit()); +} + +// Set BT session settings (user_agent) +void QBtSession::setSessionSettings(const session_settings &sessionSettings) { + qDebug("Set session settings"); + s->set_settings(sessionSettings); +} + QString QBtSession::getSavePath(const QString &hash, bool fromScanDir, QString filePath, bool imported) { QString savePath; if (TorrentTempData::hasTempData(hash)) { @@ -2923,11 +2931,6 @@ qreal QBtSession::getPayloadUploadRate() const { return s->status().payload_upload_rate; } -void QBtSession::applyEncryptionSettings(pe_settings se) { - qDebug("Applying encryption settings"); - s->set_pe_settings(se); -} - // Will fast resume torrents in // backup directory void QBtSession::startUpTorrents() { diff --git a/src/qtlibtorrent/qbtsession.h b/src/qtlibtorrent/qbtsession.h index 26b30d273..a68ff26ab 100755 --- a/src/qtlibtorrent/qbtsession.h +++ b/src/qtlibtorrent/qbtsession.h @@ -45,15 +45,50 @@ #include #include -#include -#include -#include #include "qtorrenthandle.h" #include "trackerinfos.h" #include "misc.h" -#define MAX_SAMPLES 20 +namespace libtorrent { + class add_torrent_params; + class pe_settings; + class proxy_settings; + class session; + class session_status; + + class alert; + class torrent_finished_alert; + class save_resume_data_alert; + class file_renamed_alert; + class torrent_deleted_alert; + class storage_moved_alert; + class storage_moved_failed_alert; + class metadata_received_alert; + class file_error_alert; + class file_completed_alert; + class torrent_paused_alert; + class tracker_error_alert; + class tracker_reply_alert; + class tracker_warning_alert; + class portmap_error_alert; + class portmap_alert; + class peer_blocked_alert; + class peer_ban_alert; + class fastresume_rejected_alert; + class url_seed_alert; + class listen_succeeded_alert; + class listen_failed_alert; + class torrent_checked_alert; + class external_ip_alert; + class state_update_alert; + class stats_alert; + +#if LIBTORRENT_VERSION_NUM < 10000 + class upnp; + class natpmp; +#endif +} class DownloadThread; class FilterParserThread; @@ -152,8 +187,6 @@ public slots: void setMaxRatioPerTorrent(const QString &hash, qreal ratio); qreal getMaxRatioPerTorrent(const QString &hash, bool *usesGlobalRatio) const; void removeRatioPerTorrent(const QString &hash); - void setProxySettings(libtorrent::proxy_settings proxySettings); - void setSessionSettings(const libtorrent::session_settings &sessionSettings); void setDefaultSavePath(const QString &savepath); void setDefaultTempPath(const QString &temppath); void setAppendLabelToSavePath(bool append); @@ -161,7 +194,6 @@ public slots: void changeLabelInTorrentSavePath(const QTorrentHandle &h, QString old_label, QString new_label); void appendqBextensionToTorrent(const QTorrentHandle &h, bool append); void setAppendqBExtension(bool append); - void applyEncryptionSettings(libtorrent::pe_settings se); void setDownloadLimit(QString hash, long val); void setUploadLimit(QString hash, long val); void enableUPnP(bool b); @@ -185,6 +217,9 @@ public slots: void unhideMagnet(const QString &hash); private: + void applyEncryptionSettings(libtorrent::pe_settings se); + void setProxySettings(libtorrent::proxy_settings proxySettings); + void setSessionSettings(const libtorrent::session_settings &sessionSettings); QString getSavePath(const QString &hash, bool fromScanDir = false, QString filePath = QString::null, bool imported = false); bool loadFastResumeData(const QString &hash, std::vector &buf); void loadTorrentSettings(QTorrentHandle &h); diff --git a/src/qtlibtorrent/qtorrenthandle.h b/src/qtlibtorrent/qtorrenthandle.h index ac6439cc0..a41be30c2 100644 --- a/src/qtlibtorrent/qtorrenthandle.h +++ b/src/qtlibtorrent/qtorrenthandle.h @@ -31,9 +31,7 @@ #ifndef QTORRENTHANDLE_H #define QTORRENTHANDLE_H -#include #include -#include #include diff --git a/src/qtlibtorrent/torrentmodel.cpp b/src/qtlibtorrent/torrentmodel.cpp index 419361ec1..fcaee6bd3 100644 --- a/src/qtlibtorrent/torrentmodel.cpp +++ b/src/qtlibtorrent/torrentmodel.cpp @@ -35,6 +35,8 @@ #include "qbtsession.h" #include "fs_utils.h" +#include + using namespace libtorrent; namespace { diff --git a/src/statsdialog.cpp b/src/statsdialog.cpp index bbaa43b30..f90e38716 100644 --- a/src/statsdialog.cpp +++ b/src/statsdialog.cpp @@ -32,6 +32,8 @@ #include "ui_statsdialog.h" #include "misc.h" +#include +#include StatsDialog::StatsDialog(QWidget *parent) : QDialog(parent), ui(new Ui::StatsDialog) { ui->setupUi(this); diff --git a/src/statusbar.h b/src/statusbar.h index 8c0316638..1870e87f3 100644 --- a/src/statusbar.h +++ b/src/statusbar.h @@ -46,6 +46,9 @@ #include "preferences.h" #include "misc.h" +#include +#include + class StatusBar: public QObject { Q_OBJECT diff --git a/src/webui/btjson.cpp b/src/webui/btjson.cpp index ad2be1dca..b276c1de3 100644 --- a/src/webui/btjson.cpp +++ b/src/webui/btjson.cpp @@ -39,6 +39,8 @@ #include #endif +#include + using namespace libtorrent; #if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0) diff --git a/src/webui/httpconnection.cpp b/src/webui/httpconnection.cpp index af1f619f5..00ac1c636 100644 --- a/src/webui/httpconnection.cpp +++ b/src/webui/httpconnection.cpp @@ -52,6 +52,8 @@ #include #include +#include + using namespace libtorrent; HttpConnection::HttpConnection(QTcpSocket *socket, HttpServer *parent)