From d1cbf998a0597dd49afa6da7452d19bab6a0105a Mon Sep 17 00:00:00 2001 From: Ted John Date: Fri, 27 Apr 2018 18:38:59 +0100 Subject: [PATCH] Do not return shared_ptr for LocalisationService GetLocalisationService is currently used a lot, so remove overhead of shared_ptr copy. --- src/openrct2/Context.cpp | 4 ++-- src/openrct2/Context.h | 2 +- src/openrct2/localisation/Language.cpp | 18 +++++++++--------- .../localisation/LocalisationService.cpp | 4 ++-- src/openrct2/object/ObjectRepository.cpp | 4 ++-- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/openrct2/Context.cpp b/src/openrct2/Context.cpp index c2b5612f90..78dd2837d0 100644 --- a/src/openrct2/Context.cpp +++ b/src/openrct2/Context.cpp @@ -171,9 +171,9 @@ namespace OpenRCT2 return _env; } - std::shared_ptr GetLocalisationService() override + Localisation::LocalisationService& GetLocalisationService() override { - return _localisationService; + return *_localisationService; } IObjectManager * GetObjectManager() override diff --git a/src/openrct2/Context.h b/src/openrct2/Context.h index ddf6b43bfd..9f8f151acb 100644 --- a/src/openrct2/Context.h +++ b/src/openrct2/Context.h @@ -97,7 +97,7 @@ namespace OpenRCT2 virtual std::shared_ptr GetAudioContext() abstract; virtual std::shared_ptr GetUiContext() abstract; virtual std::shared_ptr GetPlatformEnvironment() abstract; - virtual std::shared_ptr GetLocalisationService() abstract; + virtual Localisation::LocalisationService& GetLocalisationService() abstract; virtual IObjectManager * GetObjectManager() abstract; virtual IObjectRepository * GetObjectRepository() abstract; virtual ITrackDesignRepository * GetTrackDesignRepository() abstract; diff --git a/src/openrct2/localisation/Language.cpp b/src/openrct2/localisation/Language.cpp index f9d9e28006..ea67d80f7d 100644 --- a/src/openrct2/localisation/Language.cpp +++ b/src/openrct2/localisation/Language.cpp @@ -95,17 +95,17 @@ uint8 language_get_id_from_locale(const char * locale) const char * language_get_string(rct_string_id id) { const auto& localisationService = OpenRCT2::GetContext()->GetLocalisationService(); - return localisationService->GetString(id); + return localisationService.GetString(id); } bool language_open(sint32 id) { auto context = OpenRCT2::GetContext(); - const auto& localisationService = context->GetLocalisationService(); + auto& localisationService = context->GetLocalisationService(); auto objectManager = context->GetObjectManager(); try { - localisationService->OpenLanguage(id, *objectManager); + localisationService.OpenLanguage(id, *objectManager); return true; } catch (const std::exception&) @@ -117,7 +117,7 @@ bool language_open(sint32 id) bool language_get_localised_scenario_strings(const utf8 *scenarioFilename, rct_string_id *outStringIds) { const auto& localisationService = OpenRCT2::GetContext()->GetLocalisationService(); - auto result = localisationService->GetLocalisedScenarioStrings(scenarioFilename); + auto result = localisationService.GetLocalisedScenarioStrings(scenarioFilename); outStringIds[0] = std::get<0>(result); outStringIds[1] = std::get<1>(result); outStringIds[2] = std::get<2>(result); @@ -129,18 +129,18 @@ bool language_get_localised_scenario_strings(const utf8 *scenarioFilename, rct_s void language_free_object_string(rct_string_id stringId) { - const auto& localisationService = OpenRCT2::GetContext()->GetLocalisationService(); - localisationService->FreeObjectString(stringId); + auto& localisationService = OpenRCT2::GetContext()->GetLocalisationService(); + localisationService.FreeObjectString(stringId); } rct_string_id language_get_object_override_string_id(const char * identifier, uint8 index) { const auto& localisationService = OpenRCT2::GetContext()->GetLocalisationService(); - return localisationService->GetObjectOverrideStringId(identifier, index); + return localisationService.GetObjectOverrideStringId(identifier, index); } rct_string_id language_allocate_object_string(const std::string &target) { - const auto& localisationService = OpenRCT2::GetContext()->GetLocalisationService(); - return localisationService->AllocateObjectString(target); + auto& localisationService = OpenRCT2::GetContext()->GetLocalisationService(); + return localisationService.AllocateObjectString(target); } diff --git a/src/openrct2/localisation/LocalisationService.cpp b/src/openrct2/localisation/LocalisationService.cpp index 8f988577fd..1721626b2c 100644 --- a/src/openrct2/localisation/LocalisationService.cpp +++ b/src/openrct2/localisation/LocalisationService.cpp @@ -156,11 +156,11 @@ void LocalisationService::FreeObjectString(rct_string_id stringId) sint32 LocalisationService_GetCurrentLanguage() { const auto& localisationService = GetContext()->GetLocalisationService(); - return localisationService->GetCurrentLanguage(); + return localisationService.GetCurrentLanguage(); } bool LocalisationService_UseTrueTypeFont() { const auto& localisationService = GetContext()->GetLocalisationService(); - return localisationService->UseTrueTypeFont(); + return localisationService.UseTrueTypeFont(); } diff --git a/src/openrct2/object/ObjectRepository.cpp b/src/openrct2/object/ObjectRepository.cpp index 5a38ea66d7..3ef73ebd5b 100644 --- a/src/openrct2/object/ObjectRepository.cpp +++ b/src/openrct2/object/ObjectRepository.cpp @@ -667,9 +667,9 @@ const rct_object_entry * object_list_find(rct_object_entry * entry) void object_list_load() { auto context = GetContext(); - const auto localisationService = context->GetLocalisationService(); + const auto& localisationService = context->GetLocalisationService(); auto objectRepository = context->GetObjectRepository(); - objectRepository->LoadOrConstruct(localisationService->GetCurrentLanguage()); + objectRepository->LoadOrConstruct(localisationService.GetCurrentLanguage()); IObjectManager * objectManager = context->GetObjectManager(); objectManager->UnloadAll();