From 7257aee2351a71e768ab3cb4b94f75952ec181f5 Mon Sep 17 00:00:00 2001 From: Ingo Weyrich Date: Fri, 12 Jul 2019 12:56:47 +0200 Subject: [PATCH] DCPStore: use std::string instead of slow Glib::ustring --- rtengine/dcp.cc | 28 +++++++++++----------------- rtengine/dcp.h | 4 ++-- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/rtengine/dcp.cc b/rtengine/dcp.cc index 1c99b682c..56855b604 100644 --- a/rtengine/dcp.cc +++ b/rtengine/dcp.cc @@ -1833,8 +1833,7 @@ void DCPStore::init(const Glib::ustring& rt_profile_dir, bool loadAll) && lastdot <= sname.size() - 4 && !sname.casefold().compare(lastdot, 4, ".dcp") ) { - const Glib::ustring cam_short_name = sname.substr(0, lastdot).uppercase(); - file_std_profiles[cam_short_name] = fname; // They will be loaded and cached on demand + file_std_profiles[sname.substr(0, lastdot).casefold_collate_key()] = fname; // They will be loaded and cached on demand } } else { // Directory @@ -1845,11 +1844,10 @@ void DCPStore::init(const Glib::ustring& rt_profile_dir, bool loadAll) for (const auto& alias : getAliases(rt_profile_dir)) { const Glib::ustring alias_name = Glib::ustring(alias.first).uppercase(); - const Glib::ustring real_name = Glib::ustring(alias.second).uppercase(); - const std::map::const_iterator real = file_std_profiles.find(real_name); + const std::map::const_iterator real = file_std_profiles.find(Glib::ustring(alias.second).casefold_collate_key()); if (real != file_std_profiles.end()) { - file_std_profiles[alias_name] = real->second; + file_std_profiles[alias_name.casefold_collate_key()] = real->second; } } } @@ -1871,19 +1869,19 @@ bool DCPStore::isValidDCPFileName(const Glib::ustring& filename) const DCPProfile* DCPStore::getProfile(const Glib::ustring& filename) const { + const auto key = filename.casefold_collate_key(); MyMutex::MyLock lock(mutex); + const std::map::const_iterator iter = profile_cache.find(key); - const std::map::iterator r = profile_cache.find(filename); - - if (r != profile_cache.end()) { - return r->second; + if (iter != profile_cache.end()) { + return iter->second; } DCPProfile* const res = new DCPProfile(filename); if (res->isValid()) { // Add profile - profile_cache[filename] = res; + profile_cache[key] = res; if (options.rtSettings.verbose) { printf("DCP profile '%s' loaded from disk\n", filename.c_str()); } @@ -1896,13 +1894,9 @@ DCPProfile* DCPStore::getProfile(const Glib::ustring& filename) const DCPProfile* DCPStore::getStdProfile(const Glib::ustring& requested_cam_short_name) const { - const Glib::ustring name = requested_cam_short_name.uppercase(); - - // Warning: do NOT use map.find(), since it does not seem to work reliably here - for (const auto& file_std_profile : file_std_profiles) { - if (file_std_profile.first == name) { - return getProfile(file_std_profile.second); - } + const std::map::const_iterator iter = file_std_profiles.find(requested_cam_short_name.casefold_collate_key()); + if (iter != file_std_profiles.end()) { + return getProfile(iter->second); } // profile not found, looking if we're in loadAll=false mode diff --git a/rtengine/dcp.h b/rtengine/dcp.h index dc6915d26..48b881661 100644 --- a/rtengine/dcp.h +++ b/rtengine/dcp.h @@ -169,10 +169,10 @@ private: std::vector profileDir; // these contain standard profiles from RT. keys are all in uppercase, file path is value - std::map file_std_profiles; + std::map file_std_profiles; // Maps file name to profile as cache - mutable std::map profile_cache; + mutable std::map profile_cache; }; }