summaryrefslogtreecommitdiff
path: root/src/modules/m_spanningtree
diff options
context:
space:
mode:
authorattilamolnar <attilamolnar@hush.com>2012-07-04 22:56:35 +0200
committerattilamolnar <attilamolnar@hush.com>2013-04-12 21:03:04 +0200
commit7f56a39e972c9dd27826e33f0ec824dda73afd61 (patch)
tree68d720319eebdddc5eb22cfc61d173fa89c07ad3 /src/modules/m_spanningtree
parenta7b70492bb7f30ae375d2ce48684348acbaf578b (diff)
m_spanningtree Utils: Move code that creates a full line from its components to a new function
Diffstat (limited to 'src/modules/m_spanningtree')
-rw-r--r--src/modules/m_spanningtree/utils.cpp37
-rw-r--r--src/modules/m_spanningtree/utils.h4
2 files changed, 22 insertions, 19 deletions
diff --git a/src/modules/m_spanningtree/utils.cpp b/src/modules/m_spanningtree/utils.cpp
index 076d07470..aa8f74d86 100644
--- a/src/modules/m_spanningtree/utils.cpp
+++ b/src/modules/m_spanningtree/utils.cpp
@@ -202,15 +202,24 @@ void SpanningTreeUtilities::GetListOfServersForChannel(Channel* c, TreeServerLis
return;
}
-bool SpanningTreeUtilities::DoOneToAllButSender(const std::string& prefix, const std::string& command, const parameterlist& params, const std::string& omit)
+std::string SpanningTreeUtilities::ConstructLine(const std::string& prefix, const std::string& command, const parameterlist& params)
{
- TreeServer* omitroute = this->BestRouteTo(omit);
- std::string FullLine = ":" + prefix + " " + command;
- unsigned int words = params.size();
- for (unsigned int x = 0; x < words; x++)
+ std::string FullLine;
+ FullLine.reserve(MAXBUF);
+ FullLine = ":" + prefix + " " + command;
+ for (parameterlist::const_iterator x = params.begin(); x != params.end(); ++x)
{
- FullLine = FullLine + " " + params[x];
+ FullLine.push_back(' ');
+ FullLine.append(*x);
}
+ return FullLine;
+}
+
+bool SpanningTreeUtilities::DoOneToAllButSender(const std::string& prefix, const std::string& command, const parameterlist& params, const std::string& omit)
+{
+ TreeServer* omitroute = this->BestRouteTo(omit);
+ std::string FullLine = ConstructLine(prefix, command, params);
+
unsigned int items = this->TreeRoot->ChildCount();
for (unsigned int x = 0; x < items; x++)
{
@@ -231,12 +240,8 @@ bool SpanningTreeUtilities::DoOneToAllButSender(const std::string& prefix, const
bool SpanningTreeUtilities::DoOneToMany(const std::string &prefix, const std::string &command, const parameterlist &params)
{
- std::string FullLine = ":" + prefix + " " + command;
- unsigned int words = params.size();
- for (unsigned int x = 0; x < words; x++)
- {
- FullLine = FullLine + " " + params[x];
- }
+ std::string FullLine = ConstructLine(prefix, command, params);
+
unsigned int items = this->TreeRoot->ChildCount();
for (unsigned int x = 0; x < items; x++)
{
@@ -256,17 +261,11 @@ bool SpanningTreeUtilities::DoOneToOne(const std::string& prefix, const std::str
TreeServer* Route = this->BestRouteTo(target);
if (Route)
{
- std::string FullLine = ":" + prefix + " " + command;
- unsigned int words = params.size();
- for (unsigned int x = 0; x < words; x++)
- {
- FullLine = FullLine + " " + params[x];
- }
if (Route && Route->GetSocket())
{
TreeSocket* Sock = Route->GetSocket();
if (Sock)
- Sock->WriteLine(FullLine);
+ Sock->WriteLine(ConstructLine(prefix, command, params));
}
return true;
}
diff --git a/src/modules/m_spanningtree/utils.h b/src/modules/m_spanningtree/utils.h
index 8b73359c3..f3e16230a 100644
--- a/src/modules/m_spanningtree/utils.h
+++ b/src/modules/m_spanningtree/utils.h
@@ -44,6 +44,10 @@ typedef std::map<TreeServer*,TreeServer*> TreeServerList;
*/
class SpanningTreeUtilities : public classbase
{
+ /** Creates a line in the :<prefix> <command> [<params>] format
+ */
+ std::string ConstructLine(const std::string& prefix, const std::string& command, const parameterlist& params);
+
public:
/** Creator module
*/