From c48f1f789fc08429904992d4d461228542ee8ee7 Mon Sep 17 00:00:00 2001 From: Publik Date: Tue, 24 May 2022 13:46:31 -0500 Subject: [PATCH] [Player] cache find_spell lookups --- engine/player/player.cpp | 6 ++++++ engine/player/player.hpp | 1 + 2 files changed, 7 insertions(+) diff --git a/engine/player/player.cpp b/engine/player/player.cpp index aaeb1c41acd..aa9ece8478e 100644 --- a/engine/player/player.cpp +++ b/engine/player/player.cpp @@ -10250,9 +10250,15 @@ const spell_data_t* player_t::find_spell( unsigned int id ) const { if ( id ) { + auto spell_cache_entry = spell_cache.find( id ); + if ( spell_cache_entry != spell_cache.end() ) { + return spell_cache_entry->second; + } + auto spell = dbc::find_spell( this, id ); if ( spell->id() && as( spell->level() ) <= true_level ) { + spell_cache[id] = spell; return spell; } } diff --git a/engine/player/player.hpp b/engine/player/player.hpp index 3fc2a4c3fef..614ca62a3a9 100644 --- a/engine/player/player.hpp +++ b/engine/player/player.hpp @@ -718,6 +718,7 @@ struct player_t : public actor_t resource_callback_function_t callback; }; std::vector resource_callbacks; + mutable std::unordered_map spell_cache; /// Per-player custom dbc data std::unique_ptr dbc_override_;