Skip to content

Commit 147d8cf

Browse files
Qinfan Wuorionr
authored andcommitted
[Caffe2] Fix double map lookup in operator_schema.h
[Caffe2] Fix double map lookup in `operator_schema.h`.
1 parent 7b26b32 commit 147d8cf

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

caffe2/core/operator_schema.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -407,8 +407,9 @@ class OpSchemaRegistry {
407407
static OpSchema&
408408
NewSchema(const string& key, const string& file, const int line) {
409409
auto& m = map();
410-
if (m.count(key)) {
411-
const auto& schema = m[key];
410+
auto it = m.find(key);
411+
if (it != m.end()) {
412+
const auto& schema = it->second;
412413
std::ios_base::Init init;
413414
std::cerr << "Trying to register schema with name " << key
414415
<< " from file " << file << " line " << line
@@ -422,8 +423,9 @@ class OpSchemaRegistry {
422423

423424
static const OpSchema* Schema(const string& key) {
424425
auto& m = map();
425-
if (m.count(key)) {
426-
return &m[key];
426+
auto it = m.find(key);
427+
if (it != m.end()) {
428+
return &it->second;
427429
} else {
428430
return nullptr;
429431
}

0 commit comments

Comments
 (0)