summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAttila Molnar <attilamolnar@hush.com>2014-01-24 13:20:11 +0100
committerAttila Molnar <attilamolnar@hush.com>2014-01-24 13:20:11 +0100
commit458168b575663dc7bdb71c651c30320752f22e41 (patch)
tree7946216adbf9bdf252171efde9a7b9dbbe8dae3e /src
parent8537a54950a3767e54c0119a819e1ba8f8bced9e (diff)
Convert InviteBase::invites to an intrusively linked list
Diffstat (limited to 'src')
-rw-r--r--src/channels.cpp34
1 files changed, 8 insertions, 26 deletions
diff --git a/src/channels.cpp b/src/channels.cpp
index 51a8f5625..392657647 100644
--- a/src/channels.cpp
+++ b/src/channels.cpp
@@ -828,8 +828,8 @@ void Invitation::Create(Channel* c, LocalUser* u, time_t timeout)
else
{
inv = new Invitation(c, u, timeout);
- c->invites.push_back(inv);
- u->invites.push_back(inv);
+ c->invites.push_front(inv);
+ u->invites.push_front(inv);
ServerInstance->Logs->Log("INVITATION", LOG_DEBUG, "Invitation::Create created new invitation %p", (void*) inv);
}
}
@@ -840,19 +840,17 @@ Invitation* Invitation::Find(Channel* c, LocalUser* u, bool check_expired)
if (!u || u->invites.empty())
return NULL;
- InviteList locallist;
- locallist.swap(u->invites);
-
Invitation* result = NULL;
- for (InviteList::iterator i = locallist.begin(); i != locallist.end(); )
+ for (InviteList::iterator i = u->invites.begin(); i != u->invites.end(); )
{
Invitation* inv = *i;
+ ++i;
+
if ((check_expired) && (inv->expiry != 0) && (inv->expiry <= ServerInstance->Time()))
{
/* Expired invite, remove it. */
std::string expiration = InspIRCd::TimeString(inv->expiry);
ServerInstance->Logs->Log("INVITATION", LOG_DEBUG, "Invitation::Find ecountered expired entry: %p expired %s", (void*) inv, expiration.c_str());
- i = locallist.erase(i);
delete inv;
}
else
@@ -863,11 +861,9 @@ Invitation* Invitation::Find(Channel* c, LocalUser* u, bool check_expired)
result = inv;
break;
}
- ++i;
}
}
- locallist.swap(u->invites);
ServerInstance->Logs->Log("INVITATION", LOG_DEBUG, "Invitation::Find result=%p", (void*) result);
return result;
}
@@ -875,21 +871,7 @@ Invitation* Invitation::Find(Channel* c, LocalUser* u, bool check_expired)
Invitation::~Invitation()
{
// Remove this entry from both lists
- InviteList::iterator it = std::find(chan->invites.begin(), chan->invites.end(), this);
- if (it != chan->invites.end())
- chan->invites.erase(it);
- it = std::find(user->invites.begin(), user->invites.end(), this);
- if (it != user->invites.end())
- user->invites.erase(it);
-}
-
-void InviteBase::ClearInvites()
-{
- ServerInstance->Logs->Log("INVITEBASE", LOG_DEBUG, "InviteBase::ClearInvites %p", (void*) this);
- InviteList locallist;
- locallist.swap(invites);
- for (InviteList::const_iterator i = locallist.begin(); i != locallist.end(); ++i)
- {
- delete *i;
- }
+ chan->invites.erase(this);
+ user->invites.erase(this);
+ ServerInstance->Logs->Log("INVITEBASE", LOG_DEBUG, "Invitation::~ %p", (void*) this);
}