diff options
author | Haru <haru@dotalux.com> | 2019-09-23 00:05:03 +0200 |
---|---|---|
committer | Haru <haru@dotalux.com> | 2019-09-23 00:05:11 +0200 |
commit | 76f8d6ac833277c1095a234856527d9cb8a47f0d (patch) | |
tree | f1f1deb5265842d8619f8cfa922ee1d490c2dcac /src/map | |
parent | 205b602a893cb84e99ab61bafe2b84e0338acf9b (diff) | |
download | hercules-76f8d6ac833277c1095a234856527d9cb8a47f0d.tar.gz hercules-76f8d6ac833277c1095a234856527d9cb8a47f0d.tar.bz2 hercules-76f8d6ac833277c1095a234856527d9cb8a47f0d.tar.xz hercules-76f8d6ac833277c1095a234856527d9cb8a47f0d.zip |
Optimize loops in map_nick2sd
Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src/map')
-rw-r--r-- | src/map/map.c | 39 |
1 files changed, 19 insertions, 20 deletions
diff --git a/src/map/map.c b/src/map/map.c index 0f542d812..332bbe75f 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -2270,22 +2270,18 @@ static struct map_session_data *map_charid2sd(int charid) *------------------------------------------*/ static struct map_session_data *map_nick2sd(const char *nick, bool allow_partial) { - struct map_session_data* sd; - struct map_session_data* found_sd; - struct s_mapiterator* iter; - size_t nicklen; - int qty = 0; - if (nick == NULL) return NULL; - nicklen = strlen(nick); - iter = mapit_getallusers(); + struct s_mapiterator *iter = mapit_getallusers(); + struct map_session_data *found_sd = NULL; - found_sd = NULL; - for (sd = BL_UCAST(BL_PC, mapit->first(iter)); mapit->exists(iter); sd = BL_UCAST(BL_PC, mapit->next(iter))) { - if (battle_config.partial_name_scan && allow_partial) { - // partial name search + if (battle_config.partial_name_scan && allow_partial) { + int nicklen = (int)strlen(nick); + int qty = 0; + + // partial name search + for (struct map_session_data *sd = BL_UCAST(BL_PC, mapit->first(iter)); mapit->exists(iter); sd = BL_UCAST(BL_PC, mapit->next(iter))) { if (strnicmp(sd->status.name, nick, nicklen) == 0) { found_sd = sd; @@ -2297,18 +2293,21 @@ static struct map_session_data *map_nick2sd(const char *nick, bool allow_partial qty++; } - } else if (strcasecmp(sd->status.name, nick) == 0) { - // exact search only - found_sd = sd; - qty = 1; - break; + } + + if (qty != 1) + found_sd = NULL; + } else { + // exact search only + for (struct map_session_data *sd = BL_UCAST(BL_PC, mapit->first(iter)); mapit->exists(iter); sd = BL_UCAST(BL_PC, mapit->next(iter))) { + if (strcasecmp(sd->status.name, nick) == 0) { + found_sd = sd; + break; + } } } mapit->free(iter); - if (battle_config.partial_name_scan && qty != 1) - found_sd = NULL; - return found_sd; } |