mirror of
https://github.com/hrydgard/ppsspp.git
synced 2024-11-23 05:19:56 +00:00
Remove allocation on translation key lookup
This commit is contained in:
parent
10d16ea488
commit
ff0a9f2417
@ -78,10 +78,7 @@ const char *I18NCategory::T(const char *key, const char *def) {
|
||||
}
|
||||
|
||||
// Replace the \n's with \\n's so that key values with newlines will be found correctly.
|
||||
std::string modifiedKey = key;
|
||||
modifiedKey = ReplaceAll(modifiedKey, "\n", "\\n");
|
||||
|
||||
auto iter = map_.find(modifiedKey);
|
||||
auto iter = map_.find(key);
|
||||
if (iter != map_.end()) {
|
||||
return iter->second.text.c_str();
|
||||
} else {
|
||||
@ -89,7 +86,7 @@ const char *I18NCategory::T(const char *key, const char *def) {
|
||||
if (def)
|
||||
missedKeyLog_[key] = def;
|
||||
else
|
||||
missedKeyLog_[key] = modifiedKey;
|
||||
missedKeyLog_[key] = key;
|
||||
return def ? def : key;
|
||||
}
|
||||
}
|
||||
@ -97,7 +94,8 @@ const char *I18NCategory::T(const char *key, const char *def) {
|
||||
void I18NCategory::SetMap(const std::map<std::string, std::string> &m) {
|
||||
for (auto iter = m.begin(); iter != m.end(); ++iter) {
|
||||
if (map_.find(iter->first) == map_.end()) {
|
||||
std::string text = ReplaceAll(iter->second, "\\n", "\n");
|
||||
std::string text = ReplaceAll(iter->second, "\n", "\\n");
|
||||
_dbg_assert_(iter->first.find('\n') == std::string::npos);
|
||||
map_[iter->first] = I18NEntry(text);
|
||||
}
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ public:
|
||||
return missedKeyLog_;
|
||||
}
|
||||
|
||||
const std::map<std::string, I18NEntry> &GetMap() { return map_; }
|
||||
const std::map<std::string, I18NEntry, std::less<>> &GetMap() { return map_; }
|
||||
void ClearMissed() { missedKeyLog_.clear(); }
|
||||
void Clear();
|
||||
|
||||
@ -99,7 +99,7 @@ private:
|
||||
I18NCategory(I18NRepo *repo, const char *name) {}
|
||||
void SetMap(const std::map<std::string, std::string> &m);
|
||||
|
||||
std::map<std::string, I18NEntry> map_;
|
||||
std::map<std::string, I18NEntry, std::less<>> map_;
|
||||
mutable std::mutex missedKeyLock_;
|
||||
std::map<std::string, std::string> missedKeyLog_;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user