From fb5fd3f3c4788c11826dd92a36b601e9e4929014 Mon Sep 17 00:00:00 2001 From: Charles Dang Date: Thu, 30 Nov 2017 10:06:46 +1100 Subject: [PATCH] Game Events: made use of some emplace_back when constructing handlers And added a clarifying comment about types. --- src/game_events/manager_impl.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/game_events/manager_impl.cpp b/src/game_events/manager_impl.cpp index fc0e4d677b06..17420035e30a 100644 --- a/src/game_events/manager_impl.cpp +++ b/src/game_events/manager_impl.cpp @@ -110,23 +110,23 @@ void event_handlers::add_event_handler(const config& cfg, bool is_menu_item) } // Create a new handler. + // Do note active_ holds the main shared_ptr, and the other three containers + // construct weak_ptrs from the shared one. DBG_EH << "inserting event handler for name=" << name << " with id=" << id << "\n"; - handler_ptr new_handler(new event_handler(cfg, is_menu_item)); - - active_.push_back(new_handler); + active_.emplace_back(new event_handler(cfg, is_menu_item)); // File by name. if(utils::might_contain_variables(name)) { - dynamic_.push_back(new_handler); + dynamic_.emplace_back(active_.back()); } else { for(const std::string& single_name : utils::split(name)) { - by_name_[standardize_name(single_name)].push_back(new_handler); + by_name_[standardize_name(single_name)].emplace_back(active_.back()); } } // File by ID. if(!id.empty()) { - id_map_[id] = new_handler; + id_map_[id] = active_.back(); } log_handlers();