From f185257415fd9bc71aa9b355a978529609744201 Mon Sep 17 00:00:00 2001 From: "Michael Cook (mackal)" Date: Tue, 17 May 2016 17:38:08 -0400 Subject: [PATCH] Refactor ChatChannel::Invitees to std::vector --- ucs/chatchannel.cpp | 40 ++++++++++++---------------------------- ucs/chatchannel.h | 4 ++-- 2 files changed, 14 insertions(+), 30 deletions(-) diff --git a/ucs/chatchannel.cpp b/ucs/chatchannel.cpp index d7d0136e6..0aeb8379b 100644 --- a/ucs/chatchannel.cpp +++ b/ucs/chatchannel.cpp @@ -565,10 +565,9 @@ void ChatChannelList::Process() { } } -void ChatChannel::AddInvitee(std::string Invitee) { - - if(!IsInvitee(Invitee)) { - +void ChatChannel::AddInvitee(const std::string &Invitee) +{ + if (!IsInvitee(Invitee)) { Invitees.push_back(Invitee); Log.Out(Logs::Detail, Logs::UCS_Server, "Added %s as invitee to channel %s", Invitee.c_str(), Name.c_str()); @@ -576,34 +575,19 @@ void ChatChannel::AddInvitee(std::string Invitee) { } -void ChatChannel::RemoveInvitee(std::string Invitee) { +void ChatChannel::RemoveInvitee(std::string Invitee) +{ + auto it = std::find(std::begin(Invitees), std::end(Invitees), Invitee); - std::list::iterator Iterator; - - for(Iterator = Invitees.begin(); Iterator != Invitees.end(); ++Iterator) { - - if((*Iterator) == Invitee) { - - Invitees.erase(Iterator); - - Log.Out(Logs::Detail, Logs::UCS_Server, "Removed %s as invitee to channel %s", Invitee.c_str(), Name.c_str()); - - return; - } + if(it != std::end(Invitees)) { + Invitees.erase(it); + Log.Out(Logs::Detail, Logs::UCS_Server, "Removed %s as invitee to channel %s", Invitee.c_str(), Name.c_str()); } } -bool ChatChannel::IsInvitee(std::string Invitee) { - - std::list::iterator Iterator; - - for(Iterator = Invitees.begin(); Iterator != Invitees.end(); ++Iterator) { - - if((*Iterator) == Invitee) - return true; - } - - return false; +bool ChatChannel::IsInvitee(std::string Invitee) +{ + return std::find(std::begin(Invitees), std::end(Invitees), Invitee) != std::end(Invitees); } void ChatChannel::AddModerator(const std::string &Moderator) diff --git a/ucs/chatchannel.h b/ucs/chatchannel.h index 01b805eb9..89828e627 100644 --- a/ucs/chatchannel.h +++ b/ucs/chatchannel.h @@ -32,7 +32,7 @@ public: int GetMinStatus() { return MinimumStatus; } bool ReadyToDelete() { return DeleteTimer.Check(); } void SendOPList(Client *c); - void AddInvitee(std::string Invitee); + void AddInvitee(const std::string &Invitee); void RemoveInvitee(std::string Invitee); bool IsInvitee(std::string Invitee); void AddModerator(const std::string &Moderator); @@ -62,7 +62,7 @@ private: LinkedList ClientsInChannel; std::vector Moderators; - std::list Invitees; + std::vector Invitees; std::list Voiced; };