Skip to content

Commit d800a29

Browse files
committed
unordered_map is faster
1 parent d77769e commit d800a29

6 files changed

Lines changed: 9 additions & 10 deletions

File tree

src/level_monst.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Tpp Level::get_random_monst(point p, monst_environ_t monst_environ, monst_class_
6262
//
6363
TRACE_NO_INDENT();
6464
auto tp = tp_get_with_rarity_filter(tp_monst[ biome ][ monst_environ ][ monst_class ]);
65-
if (! tp) {
65+
if (unlikely(! tp)) {
6666
continue;
6767
}
6868

src/my_thing_template.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
#include "my_tile.hpp"
1313
#include <map>
1414
#include <set>
15+
#include <unordered_map>
1516

1617
using Tpidmap = std::vector< class Tp * >;
17-
using Tpnamemap = std::map< std::string, class Tp * >;
18+
using Tpnamemap = std::unordered_map< std::string, class Tp * >;
1819
using Allies = std::set< class Tp * >;
1920

2021
enum {

src/thing_init.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Thingp Level::thing_new(const std::string &name, const point at, Thingp owner)
3636
TRACE_NO_INDENT();
3737

3838
auto tp = tp_find(name);
39-
if (! tp) {
39+
if (unlikely(! tp)) {
4040
auto tp_cands = tp_find_wildcard(this, at, name);
4141
if (! tp_cands.size()) {
4242
DIE("Could not find thing '%s'", name.c_str());
@@ -51,24 +51,22 @@ Thingp Level::thing_new(const std::string &name, const point at, Thingp owner)
5151
tp = pcg_one_of(tp_cands);
5252
}
5353

54-
if (! tp) {
54+
if (unlikely(! tp)) {
5555
DIE("Could not create thing '%s'", name.c_str());
5656
return nullptr;
5757
}
5858

5959
//
6060
// Ensure things like chasms don't pile up on the same tile.
6161
//
62-
if (tp->is_one_per_tile()) {
63-
TRACE_NO_INDENT();
62+
if (unlikely(tp->is_one_per_tile())) {
6463
FOR_ALL_THINGS_AT_DEPTH(this, o, at.x, at.y, tp->z_depth)
6564
{
6665
if (o->tp() == tp) {
6766
dbg("Do not create %s as already exist at %s", name.c_str(), at.to_string().c_str());
6867
return nullptr;
6968
}
7069
}
71-
TRACE_NO_INDENT();
7270
FOR_ALL_THINGS_END()
7371
}
7472

src/thing_spawn.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ bool Thing::spawn_things_around_me(const std::string &what, int radius)
715715
}
716716

717717
auto tp = pcg_one_of(tp_cands);
718-
if (! tp) {
718+
if (unlikely(! tp)) {
719719
return false;
720720
}
721721

src/thing_template.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ Tpp tp_load(int id, std::string const &name, const std::string &text_long_name,
441441
Tilep tp_first_tile(Tpp tp)
442442
{
443443
TRACE_NO_INDENT();
444-
if (! tp) {
444+
if (unlikely(! tp)) {
445445
return nullptr;
446446
}
447447

src/thing_template_random.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ static Tpp tp_get_with_no_rarity_filter(Tpidmap &m)
647647
while (tries-- > 0) {
648648
auto index = pcg_rand() % m.size();
649649
auto tp = get(m, index);
650-
if (! tp) {
650+
if (unlikely(! tp)) {
651651
break;
652652
}
653653

0 commit comments

Comments
 (0)