summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Longbons <b.r.longbons@gmail.com>2013-09-27 21:12:53 -0700
committerBen Longbons <b.r.longbons@gmail.com>2013-09-27 21:12:53 -0700
commitd6ae15fbfae5ace5ec117c44ea1dbaa9f627c765 (patch)
tree9bf3835252c37378ecce63bbbb5eade597fe6bd9
parent638bcf8fe4d3916f0813e37d91afc4c378d56a89 (diff)
downloadtmwa-d6ae15fbfae5ace5ec117c44ea1dbaa9f627c765.tar.gz
tmwa-d6ae15fbfae5ace5ec117c44ea1dbaa9f627c765.tar.bz2
tmwa-d6ae15fbfae5ace5ec117c44ea1dbaa9f627c765.tar.xz
tmwa-d6ae15fbfae5ace5ec117c44ea1dbaa9f627c765.zip
Make character loading less slow
This is not the best solution, but it is obvious, correct, and does indeed change the complexity from O(n²) to O(n lg n).
-rw-r--r--src/char/char.cpp18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/char/char.cpp b/src/char/char.cpp
index 5f63c2a..071076e 100644
--- a/src/char/char.cpp
+++ b/src/char/char.cpp
@@ -14,6 +14,7 @@
#include <bitset>
#include <fstream>
+#include <set>
#include "../common/core.hpp"
#include "../common/cxxstdio.hpp"
@@ -374,12 +375,19 @@ bool extract(XString str, struct mmo_charstatus *p)
if (wisp_server_name == p->name)
return false;
- for (const mmo_charstatus& cd : char_data)
+ // TODO replace *every* lookup with a map lookup
+ static std::set<int> seen_ids;
+ static std::set<CharName> seen_names;
+ // we don't have to worry about deleted characters,
+ // this is only called during startup
+ auto _seen_id = seen_ids.insert(p->char_id);
+ if (!_seen_id.second)
+ return false;
+ auto _seen_name = seen_names.insert(p->name);
+ if (!_seen_name.second)
{
- if (cd.char_id == p->char_id)
- return false;
- if (cd.name == p->name)
- return false;
+ seen_ids.erase(_seen_id.first);
+ return false;
}
if (memos.size() > 10)