cataclysm-0001: overmap_ui search dedup vector O(P*M), 79x cataclysm-0002: dependency_tree dedup vector O(N^2), 2x cataclysm-0003: surroundings_menu item/terfurn dedup O(N^2), 9x
31 lines
1.3 KiB
Diff
31 lines
1.3 KiB
Diff
# UNDF: UNDF-2026-000000935
|
|
--- a/src/overmap_ui.cpp
|
|
+++ b/src/overmap_ui.cpp
|
|
@@ -1,5 +1,6 @@
|
|
// ... (includes)
|
|
#include <algorithm>
|
|
+#include <unordered_set>
|
|
|
|
// In overmap_ui::search()
|
|
// BEFORE (CWE-407): overmap_checked is std::vector with std::find for dedup
|
|
@@ -7,7 +8,7 @@
|
|
// radius = OMAPX * 5 = 900, iterating ~3.24M points
|
|
// Each std::find is O(M) where M = overmaps already checked
|
|
// Total: O(P * M) where P = points in radius, M = distinct overmaps
|
|
- std::vector<point_abs_om> overmap_checked;
|
|
+ std::unordered_set<point_abs_om> overmap_checked;
|
|
|
|
const int radius = OMAPX * 5; // arbitrary
|
|
for( const tripoint_abs_omt &p : points_in_radius( curs, radius ) ) {
|
|
@@ -16,9 +17,8 @@
|
|
tripoint_om_omt om_relative = om_loc.local;
|
|
point_abs_om om_cache = project_to<coords::om>( p.xy() );
|
|
|
|
- if( std::find( overmap_checked.begin(), overmap_checked.end(),
|
|
- om_cache ) == overmap_checked.end() ) {
|
|
- overmap_checked.push_back( om_cache );
|
|
+ if( overmap_checked.find( om_cache ) == overmap_checked.end() ) {
|
|
+ overmap_checked.insert( om_cache );
|
|
std::vector<point_abs_omt> notes = om_loc.om->find_notes( curs.z(), term );
|
|
locations.insert( locations.end(), notes.begin(), notes.end() );
|
|
}
|