Skip to content

Commit 66f5c35

Browse files
committed
speed up map loading for linux debug build
reduces "insert-rooms-area-infos" from 75 sec to 300 ms checkRemapping() is only called with members of getRoomSet(), so it's not necessary to check. This reduces "check-consistency" from 40 seconds to 850 ms
1 parent 7bfddfd commit 66f5c35

File tree

5 files changed

+8
-38
lines changed

5 files changed

+8
-38
lines changed

src/global/ImmOrderedSet.h

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include <algorithm>
99
#include <optional>
10+
#include <set>
1011
#include <stdexcept>
1112

1213
#include <immer/algorithm.hpp>
@@ -29,28 +30,9 @@ struct NODISCARD ImmOrderedSet final
2930
DEFAULT_RULE_OF_5(ImmOrderedSet);
3031

3132
public:
32-
explicit ImmOrderedSet(const Type id)
33-
: m_vector{id}
33+
explicit ImmOrderedSet(const std::set<T> &from)
34+
: m_vector{from.begin(), from.end()}
3435
{}
35-
explicit ImmOrderedSet(const Vector &other)
36-
: m_vector{other}
37-
{}
38-
explicit ImmOrderedSet(Vector &&other)
39-
: m_vector{std::move(other)}
40-
{}
41-
42-
ImmOrderedSet &operator=(const Vector &other)
43-
{
44-
if (m_vector == other)
45-
return *this;
46-
m_vector = other;
47-
return *this;
48-
}
49-
ImmOrderedSet &operator=(Vector &&other)
50-
{
51-
m_vector = std::move(other);
52-
return *this;
53-
}
5436

5537
public:
5638
NODISCARD size_t size() const { return m_vector.size(); }

src/map/RoomIdSet.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,6 @@ void runRoomIdSetTests()
2020
TEST_ASSERT(!defaultConstructorSet.contains(RoomId(1)));
2121
TEST_ASSERT(defaultConstructorSet.begin() == defaultConstructorSet.end());
2222

23-
RoomId singleId(42);
24-
Type setWithSingleId(singleId);
25-
TEST_ASSERT(!setWithSingleId.empty());
26-
TEST_ASSERT(setWithSingleId.size() == 1ULL);
27-
TEST_ASSERT(setWithSingleId.contains(singleId));
28-
TEST_ASSERT(!setWithSingleId.contains(RoomId(1)));
29-
TEST_ASSERT(*setWithSingleId.begin() == singleId);
30-
TEST_ASSERT(*setWithSingleId.begin() == singleId);
31-
3223
Type setForInsert;
3324
setForInsert.insert(RoomId(10));
3425
TEST_ASSERT(!setForInsert.empty());

src/map/World.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -638,10 +638,6 @@ void World::checkConsistency(ProgressCounter &counter) const
638638
};
639639

640640
auto checkRemapping = [this](const RoomId id) {
641-
if (!getRoomSet().contains(id)) {
642-
throw MapConsistencyError("room set does not contain the room id");
643-
}
644-
645641
const auto &area = getRoomArea(id);
646642
if (!getArea(area).contains(id)) {
647643
throw MapConsistencyError("room set does not contain the room id");
@@ -1210,7 +1206,7 @@ World World::init(ProgressCounter &counter,
12101206
DECL_TIMER(t3, "insert-rooms-area-infos");
12111207
counter.setNewTask(ProgressMsg{"preparing to insert rooms to areas"}, rooms.size());
12121208
std::unordered_map<RoomArea, AreaInfo> map;
1213-
ImmRoomIdSet global;
1209+
std::set<RoomId> global;
12141210
for (const auto &room : rooms) {
12151211
map[room.getArea()].roomSet.insert(room.id);
12161212
global.insert(room.id);

src/map/WorldAreaMap.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@ AreaInfoMap::AreaInfoMap()
2727
assert(find(RoomArea{}) != nullptr);
2828
}
2929

30-
void AreaInfoMap::init(const std::unordered_map<RoomArea, AreaInfo> &map, const ImmRoomIdSet &global)
30+
void AreaInfoMap::init(const std::unordered_map<RoomArea, AreaInfo> &map,
31+
const std::set<RoomId> &global)
3132
{
3233
m_map.init(map);
33-
m_global = global;
34+
m_global = ImmRoomIdSet{global};
3435
}
3536

3637
const AreaInfo *AreaInfoMap::find(const RoomArea &area) const

src/map/WorldAreaMap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ struct NODISCARD AreaInfoMap final
3131

3232
public:
3333
NODISCARD explicit AreaInfoMap();
34-
void init(const std::unordered_map<RoomArea, AreaInfo> &map, const ImmRoomIdSet &global);
34+
void init(const std::unordered_map<RoomArea, AreaInfo> &map, const std::set<RoomId> &global);
3535

3636
public:
3737
NODISCARD const ImmRoomIdSet &getGlobal() const { return m_global; }

0 commit comments

Comments
 (0)