Skip to content

Commit c58b9d8

Browse files
Selatsapier
Selat
authored and
sapier
committedAug 22, 2014
ban.cpp refactoring
1 parent dec8c43 commit c58b9d8

File tree

1 file changed

+10
-19
lines changed

1 file changed

+10
-19
lines changed
 

‎src/ban.cpp

+10-19
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,16 @@ void BanManager::load()
5757
throw SerializationError("BanManager::load(): Couldn't open file");
5858
}
5959

60-
for(;;)
60+
while(!is.eof() && is.good())
6161
{
62-
if(is.eof() || is.good() == false)
63-
break;
6462
std::string line;
6563
std::getline(is, line, '\n');
6664
Strfnd f(line);
6765
std::string ip = trim(f.next("|"));
6866
std::string name = trim(f.next("|"));
69-
if(ip.empty())
70-
continue;
71-
m_ips[ip] = name;
67+
if(!ip.empty()) {
68+
m_ips[ip] = name;
69+
}
7270
}
7371
m_modified = false;
7472
}
@@ -135,22 +133,15 @@ void BanManager::add(const std::string &ip, const std::string &name)
135133
void BanManager::remove(const std::string &ip_or_name)
136134
{
137135
JMutexAutoLock lock(m_mutex);
138-
//m_ips.erase(m_ips.find(ip));
139-
// Find out all ip-name pairs that match the ip or name
140-
std::set<std::string> ips_to_delete;
141136
for(std::map<std::string, std::string>::iterator
142137
i = m_ips.begin();
143-
i != m_ips.end(); i++)
144-
{
145-
if(i->first == ip_or_name || i->second == ip_or_name)
146-
ips_to_delete.insert(i->first);
147-
}
148-
// Erase them
149-
for(std::set<std::string>::iterator
150-
i = ips_to_delete.begin();
151-
i != ips_to_delete.end(); i++)
138+
i != m_ips.end();)
152139
{
153-
m_ips.erase(*i);
140+
if((i->first == ip_or_name) || (i->second == ip_or_name)) {
141+
m_ips.erase(i++);
142+
} else {
143+
++i;
144+
}
154145
}
155146
m_modified = true;
156147
}

0 commit comments

Comments
 (0)
Please sign in to comment.