Index: chrome/browser/chromeos/input_method/input_method_util.cc |
diff --git a/chrome/browser/chromeos/input_method/input_method_util.cc b/chrome/browser/chromeos/input_method/input_method_util.cc |
index 48085cf98931c9485e74505234aaba3fa7736df7..89ef419cfcb8d1a7f02d7181638ab985237c04a4 100644 |
--- a/chrome/browser/chromeos/input_method/input_method_util.cc |
+++ b/chrome/browser/chromeos/input_method/input_method_util.cc |
@@ -379,13 +379,20 @@ InputMethodUtil::InputMethodUtil(InputMethodDelegate* delegate) |
ResetInputMethods(default_input_methods); |
// Initialize a map from English string to Chrome string resource ID as well. |
+ // Since this array is write-once, initialize a flat map in one step with a |
+ // given vector storage. |
+ std::vector<EnglishToIDMap::value_type> map_storage; |
+ map_storage.reserve(kEnglishToResourceIdArraySize); |
for (size_t i = 0; i < kEnglishToResourceIdArraySize; ++i) { |
const EnglishToResouceId& map_entry = kEnglishToResourceIdArray[i]; |
- const bool result = english_to_resource_id_.insert(std::make_pair( |
- map_entry.english_string_from_ibus, map_entry.resource_id)).second; |
- DCHECK(result) << "Duplicated string is found: " |
- << map_entry.english_string_from_ibus; |
+ map_storage.emplace_back(map_entry.english_string_from_ibus, |
+ map_entry.resource_id); |
chrisha
2017/05/23 20:07:59
nit: Instead of dynamically creating a const flat_
brettw
2017/06/28 23:58:39
That would be better but I just spent 2 hours on t
|
} |
+ |
+ english_to_resource_id_ = |
+ EnglishToIDMap(std::move(map_storage), base::KEEP_FIRST_OF_DUPES); |
+ DCHECK(english_to_resource_id_.size() == kEnglishToResourceIdArraySize) |
+ << "Duplicate string is found"; |
} |
InputMethodUtil::~InputMethodUtil() { |
@@ -415,7 +422,7 @@ bool InputMethodUtil::TranslateStringInternal( |
// to get the translated string. |
std::string key_string = extension_ime_util::MaybeGetLegacyXkbId( |
english_string); |
- HashType::const_iterator iter = english_to_resource_id_.find(key_string); |
+ auto iter = english_to_resource_id_.find(key_string); |
chrisha
2017/05/23 20:07:59
Just use std::binary_search?
|
if (iter == english_to_resource_id_.end()) { |
// TODO(yusukes): Write Autotest which checks if all display names and all |