From d6ae15fbfae5ace5ec117c44ea1dbaa9f627c765 Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Fri, 27 Sep 2013 21:12:53 -0700 Subject: Make character loading less slow MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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). --- src/char/char.cpp | 18 +++++++++++++----- 1 file 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 #include +#include #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 seen_ids; + static std::set 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) -- cgit v1.2.3-60-g2f50