Skip to content

Commit

Permalink
Merge bitcoin#13961: util: Replace boost::signals2 with std::function
Browse files Browse the repository at this point in the history
ddddce0 util: Replace boost::signals2 with std::function (MarcoFalke)

Pull request description:

  This removes the `#include <boost/signals2/signal.hpp>` from `util.h` (hopefully speeding up the build time and reducing the memory usage further after  bitcoin#13634)

  The whole translation interface is replaced by a function `G_TRANSLATION_FUN` that is set to nullptr in units that don't need translation. (Thus only set in the gui)

Tree-SHA512: 087c717358bbed8bdb409463e225239d667f1ced381abb10e7cd31a41dcdd2cebe20b43c2ee86f0f8e55d53301f75e963f07421a99a7ff4c0cad2c6a375c5ab1

# Conflicts:
#	src/bench/bench_dash.cpp
#	src/qt/dash.cpp
#	src/qt/splashscreen.cpp
#	src/qt/transactiontablemodel.cpp
#	src/test/test_dash.cpp
#	src/util/system.h
#	src/wallet/coinselection.cpp
  • Loading branch information
laanwj authored and Munkybooty committed Jun 29, 2021
1 parent 3d05f2a commit e86ea61
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 36 deletions.
2 changes: 2 additions & 0 deletions src/bench/bench_dash.cpp
Expand Up @@ -16,6 +16,8 @@

#include <bls/bls.h>

const std::function<std::string(const char*)> G_TRANSLATION_FUN = nullptr;

static const int64_t DEFAULT_BENCH_EVALUATIONS = 5;
static const char* DEFAULT_BENCH_FILTER = ".*";
static const char* DEFAULT_BENCH_SCALING = "1.0";
Expand Down
2 changes: 2 additions & 0 deletions src/dash-cli.cpp
Expand Up @@ -26,6 +26,8 @@

#include <univalue.h>

const std::function<std::string(const char*)> G_TRANSLATION_FUN = nullptr;

static const char DEFAULT_RPCCONNECT[] = "127.0.0.1";
static const int DEFAULT_HTTP_CLIENT_TIMEOUT=900;
static const bool DEFAULT_NAMED=false;
Expand Down
2 changes: 2 additions & 0 deletions src/dash-tx.cpp
Expand Up @@ -32,6 +32,8 @@ static bool fCreateBlank;
static std::map<std::string,UniValue> registers;
static const int CONTINUE_EXECUTION=-1;

const std::function<std::string(const char*)> G_TRANSLATION_FUN = nullptr;

static void SetupBitcoinTxArgs()
{
gArgs.AddArg("-?", "This help message", false, OptionsCategory::OPTIONS);
Expand Down
2 changes: 2 additions & 0 deletions src/dashd.cpp
Expand Up @@ -25,6 +25,8 @@

#include <stdio.h>

const std::function<std::string(const char*)> G_TRANSLATION_FUN = nullptr;

/* Introduction text for doxygen: */

/*! \mainpage Developer documentation
Expand Down
2 changes: 2 additions & 0 deletions src/noui.cpp
Expand Up @@ -13,6 +13,8 @@
#include <stdint.h>
#include <string>

#include <boost/signals2/connection.hpp>

static bool noui_ThreadSafeMessageBox(const std::string& message, const std::string& caption, unsigned int style)
{
bool fSecure = style & CClientUIInterface::SECURE;
Expand Down
2 changes: 2 additions & 0 deletions src/qt/bitcoingui.cpp
Expand Up @@ -61,6 +61,8 @@
#include <QUrlQuery>
#include <QVBoxLayout>

#include <boost/bind.hpp>

const std::string BitcoinGUI::DEFAULT_UIPLATFORM =
#if defined(Q_OS_MAC)
"macosx"
Expand Down
10 changes: 3 additions & 7 deletions src/qt/dash.cpp
Expand Up @@ -76,13 +76,10 @@ static void InitMessage(const std::string &message)
LogPrintf("init message: %s\n", message);
}

/*
Translate string to current locale using Qt.
*/
static std::string Translate(const char* psz)
{
/** Translate string to current locale using Qt. */
const std::function<std::string(const char*)> G_TRANSLATION_FUN = [](const char* psz) {
return QCoreApplication::translate("dash-core", psz).toStdString();
}
};

static QString GetLangTerritory()
{
Expand Down Expand Up @@ -628,7 +625,6 @@ int main(int argc, char *argv[])
// Now that QSettings are accessible, initialize translations
QTranslator qtTranslatorBase, qtTranslator, translatorBase, translator;
initTranslations(qtTranslatorBase, qtTranslator, translatorBase, translator);
translationInterface.Translate.connect(Translate);

if (gArgs.IsArgSet("-printcrashinfo")) {
auto crashInfo = GetCrashInfoStrFromSerializedStr(gArgs.GetArg("-printcrashinfo", ""));
Expand Down
4 changes: 3 additions & 1 deletion src/qt/splashscreen.cpp
Expand Up @@ -18,15 +18,17 @@
#include <interfaces/handler.h>
#include <interfaces/node.h>
#include <interfaces/wallet.h>
#include <util/system.h>
#include <ui_interface.h>
#include <util/system.h>
#include <version.h>

#include <QApplication>
#include <QCloseEvent>
#include <QDesktopWidget>
#include <QPainter>

#include <boost/bind.hpp>

SplashScreen::SplashScreen(interfaces::Node& node, Qt::WindowFlags f, const NetworkStyle *networkStyle) :
QWidget(0, f), curAlignment(0), m_node(node)
{
Expand Down
4 changes: 3 additions & 1 deletion src/qt/transactiontablemodel.cpp
Expand Up @@ -13,17 +13,19 @@
#include <core_io.h>
#include <interfaces/handler.h>
#include <interfaces/node.h>
#include <validation.h>
#include <sync.h>
#include <uint256.h>
#include <util/system.h>
#include <validation.h>

#include <QColor>
#include <QDateTime>
#include <QDebug>
#include <QIcon>
#include <QList>

#include <boost/bind.hpp>

// Amount column is right-aligned it contains numbers
static int column_alignments[] = {
Qt::AlignLeft|Qt::AlignVCenter, /* status */
Expand Down
11 changes: 7 additions & 4 deletions src/test/test_dash.cpp
Expand Up @@ -9,15 +9,16 @@
#include <consensus/validation.h>
#include <crypto/sha256.h>
#include <index/txindex.h>
#include <validation.h>
#include <miner.h>
#include <net_processing.h>
#include <pow.h>
#include <ui_interface.h>
#include <streams.h>
#include <rpc/server.h>
#include <rpc/register.h>
#include <rpc/server.h>
#include <script/sigcache.h>
#include <streams.h>
#include <ui_interface.h>
#include <validation.h>

#include <util/validation.h>

#include <coinjoin/coinjoin.h>
Expand All @@ -26,6 +27,8 @@
#include <evo/cbtx.h>
#include <llmq/quorums_init.h>

const std::function<std::string(const char*)> G_TRANSLATION_FUN = nullptr;

void CConnmanTest::AddNode(CNode& node)
{
LOCK(g_connman->cs_vNodes);
Expand Down
12 changes: 7 additions & 5 deletions src/test/test_dash_fuzzy.cpp
Expand Up @@ -6,20 +6,20 @@
#include <config/dash-config.h>
#endif

#include <consensus/merkle.h>
#include <primitives/block.h>
#include <script/script.h>
#include <addrman.h>
#include <blockencodings.h>
#include <chain.h>
#include <coins.h>
#include <compressor.h>
#include <consensus/merkle.h>
#include <net.h>
#include <primitives/block.h>
#include <protocol.h>
#include <pubkey.h>
#include <script/script.h>
#include <streams.h>
#include <undo.h>
#include <version.h>
#include <pubkey.h>
#include <blockencodings.h>

#include <stdint.h>
#include <unistd.h>
Expand All @@ -28,6 +28,8 @@
#include <memory>
#include <vector>

const std::function<std::string(const char*)> G_TRANSLATION_FUN = nullptr;

enum TEST_ID {
CBLOCK_DESERIALIZE=0,
CTRANSACTION_DESERIALIZE,
Expand Down
2 changes: 0 additions & 2 deletions src/util/system.cpp
Expand Up @@ -99,8 +99,6 @@ const char * const BITCOIN_PID_FILENAME = "dashd.pid";

ArgsManager gArgs;

CTranslationInterface translationInterface;

/** Init OpenSSL library multithreading support */
static std::unique_ptr<CCriticalSection[]> ppmutexOpenSSL;
void locking_callback(int mode, int i, const char* file, int line) NO_THREAD_SAFETY_ANALYSIS
Expand Down
23 changes: 7 additions & 16 deletions src/util/system.h
Expand Up @@ -22,8 +22,8 @@
#include <sync.h>
#include <util/threadnames.h>
#include <tinyformat.h>
#include <util/time.h>
#include <util/memory.h>
#include <util/time.h>
#include <amount.h>

#include <atomic>
Expand All @@ -36,7 +36,6 @@
#include <unordered_set>
#include <vector>

#include <boost/signals2/signal.hpp>
#include <boost/thread/condition_variable.hpp> // for boost::thread_interrupted

// Debugging macros
Expand All @@ -59,27 +58,19 @@ extern int nWalletBackups;
// Application startup time (used for uptime calculation)
int64_t GetStartupTime();

/** Signals for translation. */
class CTranslationInterface
{
public:
/** Translate a message to the native language of the user. */
boost::signals2::signal<std::string (const char* psz)> Translate;
};

extern CTranslationInterface translationInterface;

extern const char * const BITCOIN_CONF_FILENAME;
extern const char * const BITCOIN_PID_FILENAME;

/** Translate a message to the native language of the user. */
const extern std::function<std::string(const char*)> G_TRANSLATION_FUN;

/**
* Translation function: Call Translate signal on UI interface, which returns a boost::optional result.
* If no translation slot is registered, nothing is returned, and simply return the input.
* Translation function.
* If no translation function is set, simply return the input.
*/
inline std::string _(const char* psz)
{
boost::optional<std::string> rv = translationInterface.Translate(psz);
return rv ? (*rv) : psz;
return G_TRANSLATION_FUN ? (G_TRANSLATION_FUN)(psz) : psz;
}

void SetupEnvironment();
Expand Down
1 change: 1 addition & 0 deletions src/wallet/coinselection.cpp
Expand Up @@ -3,6 +3,7 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <wallet/coinselection.h>

#include <util/system.h>
#include <util/moneystr.h>

Expand Down

0 comments on commit e86ea61

Please sign in to comment.