Replace ke::LinkedList with std::list.

This commit is contained in:
David Anderson 2020-05-31 11:59:54 -07:00
parent d5d4d78023
commit 80acff8d7d
7 changed files with 37 additions and 38 deletions

View File

@ -45,7 +45,7 @@ using namespace ke;
ConCmdManager g_ConCmds; ConCmdManager g_ConCmds;
typedef ke::LinkedList<CmdHook *> PluginHookList; typedef std::list<CmdHook *> PluginHookList;
void RegisterInPlugin(CmdHook *hook); void RegisterInPlugin(CmdHook *hook);
ConCmdManager::ConCmdManager() ConCmdManager::ConCmdManager()
@ -381,7 +381,7 @@ bool ConCmdManager::AddAdminCommand(IPluginFunction *pFunction,
pHook->admin->eflags = pHook->admin->flags; pHook->admin->eflags = pHook->admin->flags;
pInfo->eflags = pHook->admin->eflags; pInfo->eflags = pHook->admin->eflags;
cmdgroup->hooks.append(pHook); cmdgroup->hooks.push_back(pHook);
pInfo->hooks.append(pHook); pInfo->hooks.append(pHook);
RegisterInPlugin(pHook); RegisterInPlugin(pHook);
return true; return true;
@ -426,13 +426,13 @@ void RegisterInPlugin(CmdHook *hook)
const char *cmd = (*iter)->info->pCmd->GetName(); const char *cmd = (*iter)->info->pCmd->GetName();
if (strcmp(orig, cmd) < 0) if (strcmp(orig, cmd) < 0)
{ {
pList->insertBefore(iter, hook); pList->emplace(iter, hook);
return; return;
} }
iter++; iter++;
} }
pList->append(hook); pList->emplace_back(hook);
} }
void ConCmdManager::AddToCmdList(ConCmdInfo *info) void ConCmdManager::AddToCmdList(ConCmdInfo *info)

View File

@ -32,8 +32,14 @@
#ifndef _INCLUDE_SOURCEMOD_CONCMDMANAGER_H_ #ifndef _INCLUDE_SOURCEMOD_CONCMDMANAGER_H_
#define _INCLUDE_SOURCEMOD_CONCMDMANAGER_H_ #define _INCLUDE_SOURCEMOD_CONCMDMANAGER_H_
#include <list>
#include <memory> #include <memory>
#include <am-inlinelist.h>
#include <am-refcounting.h>
#include <am-utility.h>
#include <sm_stringhashmap.h>
#include "sm_globals.h" #include "sm_globals.h"
#include "sourcemm_api.h" #include "sourcemm_api.h"
#include <IForwardSys.h> #include <IForwardSys.h>
@ -43,11 +49,6 @@
#include <IAdminSystem.h> #include <IAdminSystem.h>
#include "concmd_cleaner.h" #include "concmd_cleaner.h"
#include "GameHooks.h" #include "GameHooks.h"
#include <sm_stringhashmap.h>
#include <am-utility.h>
#include <am-inlinelist.h>
#include <am-linkedlist.h>
#include <am-refcounting.h>
using namespace SourceHook; using namespace SourceHook;
@ -56,7 +57,7 @@ struct ConCmdInfo;
struct CommandGroup : public ke::Refcounted<CommandGroup> struct CommandGroup : public ke::Refcounted<CommandGroup>
{ {
ke::LinkedList<CmdHook *> hooks; std::list<CmdHook *> hooks;
}; };
struct AdminCmdInfo struct AdminCmdInfo

View File

@ -61,7 +61,7 @@ IForward *CForwardManager::CreateForward(const char *name, ExecType et, unsigned
{ {
scripts->AddFunctionsToForward(name, fwd); scripts->AddFunctionsToForward(name, fwd);
m_managed.append(fwd); m_managed.push_back(fwd);
} }
return fwd; return fwd;
@ -78,7 +78,7 @@ IChangeableForward *CForwardManager::CreateForwardEx(const char *name, ExecType
if (fwd) if (fwd)
{ {
m_unmanaged.append(fwd); m_unmanaged.push_back(fwd);
} }
return fwd; return fwd;
@ -751,9 +751,9 @@ bool CForward::AddFunction(IPluginFunction *func)
return false; return false;
if (func->IsRunnable()) if (func->IsRunnable())
m_functions.append(func); m_functions.push_back(func);
else else
m_paused.append(func); m_paused.push_back(func);
return true; return true;
} }
@ -780,7 +780,7 @@ const char *CForward::GetForwardName()
unsigned int CForward::GetFunctionCount() unsigned int CForward::GetFunctionCount()
{ {
return m_functions.length(); return m_functions.size();
} }
ExecType CForward::GetExecType() ExecType CForward::GetExecType()

View File

@ -33,7 +33,6 @@
#include <sp_vm_types.h> #include <sp_vm_types.h>
#include <sh_list.h> #include <sh_list.h>
#include <am-linkedlist.h>
#include <am-vector.h> #include <am-vector.h>
#include "common_logic.h" #include "common_logic.h"
#include "Native.h" #include "Native.h"

View File

@ -45,7 +45,6 @@
#include "Logger.h" #include "Logger.h"
#include "frame_tasks.h" #include "frame_tasks.h"
#include <amtl/am-string.h> #include <amtl/am-string.h>
#include <amtl/am-linkedlist.h>
#include <bridge/include/IVEngineServerBridge.h> #include <bridge/include/IVEngineServerBridge.h>
#include <bridge/include/CoreProvider.h> #include <bridge/include/CoreProvider.h>
@ -790,7 +789,7 @@ void CPlugin::BindFakeNativesTo(CPlugin *other)
CPluginManager::CPluginIterator::CPluginIterator(ReentrantList<CPlugin *>& in) CPluginManager::CPluginIterator::CPluginIterator(ReentrantList<CPlugin *>& in)
{ {
for (PluginIter iter(in); !iter.done(); iter.next()) for (PluginIter iter(in); !iter.done(); iter.next())
mylist.append(*iter); mylist.push_back(*iter);
current = mylist.begin(); current = mylist.begin();
g_PluginSys.AddPluginsListener(this); g_PluginSys.AddPluginsListener(this);
} }
@ -1033,7 +1032,7 @@ void CPluginManager::LoadAutoPlugin(const char *plugin)
void CPluginManager::AddPlugin(CPlugin *pPlugin) void CPluginManager::AddPlugin(CPlugin *pPlugin)
{ {
m_plugins.append(pPlugin); m_plugins.push_back(pPlugin);
m_LoadLookup.insert(pPlugin->GetFilename(), pPlugin); m_LoadLookup.insert(pPlugin->GetFilename(), pPlugin);
pPlugin->SetRegistered(); pPlugin->SetRegistered();
@ -1536,12 +1535,12 @@ CPlugin *CPluginManager::GetPluginByCtx(const sp_context_t *ctx)
unsigned int CPluginManager::GetPluginCount() unsigned int CPluginManager::GetPluginCount()
{ {
return m_plugins.length(); return m_plugins.size();
} }
void CPluginManager::AddPluginsListener(IPluginsListener *listener) void CPluginManager::AddPluginsListener(IPluginsListener *listener)
{ {
m_listeners.append(listener); m_listeners.push_back(listener);
} }
void CPluginManager::RemovePluginsListener(IPluginsListener *listener) void CPluginManager::RemovePluginsListener(IPluginsListener *listener)
@ -1715,7 +1714,7 @@ void CPluginManager::OnRootConsoleCommand(const char *cmdname, const ICommandArg
rootmenu->ConsolePrint("[SM] Listing %d plugin%s:", plnum, (plnum > 1) ? "s" : ""); rootmenu->ConsolePrint("[SM] Listing %d plugin%s:", plnum, (plnum > 1) ? "s" : "");
} }
ke::LinkedList<CPlugin *> fail_list; std::list<CPlugin *> fail_list;
for (PluginIter iter(m_plugins); !iter.done(); iter.next(), id++) { for (PluginIter iter(m_plugins); !iter.done(); iter.next(), id++) {
CPlugin *pl = (*iter); CPlugin *pl = (*iter);
@ -1727,7 +1726,7 @@ void CPluginManager::OnRootConsoleCommand(const char *cmdname, const ICommandArg
len += ke::SafeSprintf(buffer, sizeof(buffer), " %0*d <%s>", plpadding, id, GetStatusText(pl->GetDisplayStatus())); len += ke::SafeSprintf(buffer, sizeof(buffer), " %0*d <%s>", plpadding, id, GetStatusText(pl->GetDisplayStatus()));
/* Plugin has failed to load. */ /* Plugin has failed to load. */
fail_list.append(pl); fail_list.push_back(pl);
} }
else else
{ {
@ -2351,7 +2350,7 @@ public:
{ {
ke::RefPtr<PluginsListenerV1Wrapper> wrapper = new PluginsListenerV1Wrapper(listener); ke::RefPtr<PluginsListenerV1Wrapper> wrapper = new PluginsListenerV1Wrapper(listener);
v1_wrappers_.append(wrapper); v1_wrappers_.push_back(wrapper);
g_PluginSys.AddPluginsListener(wrapper); g_PluginSys.AddPluginsListener(wrapper);
} }

View File

@ -320,8 +320,8 @@ public:
void Release(); void Release();
void OnPluginDestroyed(IPlugin *plugin) override; void OnPluginDestroyed(IPlugin *plugin) override;
private: private:
ke::LinkedList<CPlugin *> mylist; std::list<CPlugin *> mylist;
ke::LinkedList<CPlugin *>::iterator current; std::list<CPlugin *>::iterator current;
}; };
friend class CPluginManager::CPluginIterator; friend class CPluginManager::CPluginIterator;
public: //IScriptManager public: //IScriptManager
@ -476,7 +476,7 @@ private:
private: private:
ReentrantList<IPluginsListener *> m_listeners; ReentrantList<IPluginsListener *> m_listeners;
ReentrantList<CPlugin *> m_plugins; ReentrantList<CPlugin *> m_plugins;
ke::LinkedList<CPluginIterator *> m_iterators; std::list<CPluginIterator *> m_iterators;
typedef decltype(m_listeners)::iterator ListenerIter; typedef decltype(m_listeners)::iterator ListenerIter;
typedef decltype(m_plugins)::iterator PluginIter; typedef decltype(m_plugins)::iterator PluginIter;

View File

@ -27,14 +27,15 @@
#ifndef _include_sourcemod_reentrant_iterator_h_ #ifndef _include_sourcemod_reentrant_iterator_h_
#define _include_sourcemod_reentrant_iterator_h_ #define _include_sourcemod_reentrant_iterator_h_
#include <algorithm>
#include <list>
#include <utility> #include <utility>
#include <amtl/am-linkedlist.h>
#include <amtl/am-function.h> #include <amtl/am-function.h>
namespace SourceMod { namespace SourceMod {
// ReentrantList is a wrapper around a LinkedList, with special attention twoard // ReentrantList is a wrapper around a std::list, with special attention twoard
// reentrancy. The list may be mutated during iteration as long as its iterator // reentrancy. The list may be mutated during iteration as long as its iterator
// protocol is obeyed: iterators may only be used on the stack in a LIFO manner, // protocol is obeyed: iterators may only be used on the stack in a LIFO manner,
// and it is illegal to request access to an iterator's item after the list has // and it is illegal to request access to an iterator's item after the list has
@ -43,16 +44,15 @@ namespace SourceMod {
// We guard against this using assertions. If an item in a list is removed, and // We guard against this using assertions. If an item in a list is removed, and
// this affects any active iterators, those iterators cannot be used until their // this affects any active iterators, those iterators cannot be used until their
// next() function is called. // next() function is called.
template <typename T, class AllocPolicy = ke::SystemAllocatorPolicy> template <typename T>
class ReentrantList : public ke::LinkedList<T, AllocPolicy> class ReentrantList : public std::list<T>
{ {
typedef typename ke::LinkedList<T> BaseType; typedef typename std::list<T> BaseType;
typedef typename ke::LinkedList<T>::iterator BaseTypeIter; typedef typename std::list<T>::iterator BaseTypeIter;
public: public:
ReentrantList(AllocPolicy ap = AllocPolicy()) ReentrantList()
: ke::LinkedList<T, AllocPolicy>(ap), : top_(nullptr)
top_(nullptr)
{ {
} }
@ -150,12 +150,12 @@ public:
template <typename U> template <typename U>
void insertBefore(iterator& where, U &&obj) { void insertBefore(iterator& where, U &&obj) {
BaseType::insertBefore(where.impl_, std::forward<U>(obj)); BaseType::insert(where.impl_, std::forward<U>(obj));
} }
template <typename U> template <typename U>
bool contains(const U &obj) { bool contains(const U &obj) {
return BaseType::find(obj) != BaseType::end(); return std::find(BaseType::begin(), BaseType::end(), obj) != BaseType::end();
} }
private: private: