Skip to content

Commit 69247a0

Browse files
authored
Merge pull request #134 from pps83/master-codecmap-find
Search CODECFactory::scodecmap only once
2 parents 78d44ed + d36d0f4 commit 69247a0

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

src/codecfactory.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,17 @@ std::vector<std::string> CODECFactory::allNames() const {
4646
}
4747

4848
std::shared_ptr<IntegerCODEC> const& CODECFactory::getFromName(std::string name) const {
49-
if (scodecmap.find(name) == scodecmap.end()) {
50-
fprintf(stderr, "name %s does not refer to a CODEC.\n"
51-
"possible choices:\n", name.c_str());
52-
for (auto i = scodecmap.begin(); i != scodecmap.end(); ++i) {
53-
fprintf(stderr, "%s\n", i->first.c_str());
54-
}
55-
fprintf(stderr, "for now, I'm going to just return 'copy'\n");
56-
return scodecmap.at("copy");
49+
auto it = scodecmap.find(name);
50+
if (it != scodecmap.end())
51+
return it->second;
52+
53+
fprintf(stderr, "name %s does not refer to a CODEC.\n"
54+
"possible choices:\n", name.c_str());
55+
for (auto i = scodecmap.begin(); i != scodecmap.end(); ++i) {
56+
fprintf(stderr, "%s\n", i->first.c_str());
5757
}
58-
return scodecmap.at(name);
58+
fprintf(stderr, "for now, I'm going to just return 'copy'\n");
59+
return scodecmap.at("copy");
5960
}
6061

6162
std::unique_ptr<IntegerCODEC> fastbinarypacking8_codec() {

0 commit comments

Comments
 (0)