diff options
author | lloyd <[email protected]> | 2006-06-11 01:08:02 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2006-06-11 01:08:02 +0000 |
commit | 073cb7b3a610d2bd1c9fdd6f513c299abb708d14 (patch) | |
tree | 24f052c55a06c7c0a283946b61c5da938382ef2e | |
parent | 60822d6d59408f8836909c2c70a04055c3f81e67 (diff) |
Use equal_range instead of linear search in Data_Store::get
-rw-r--r-- | src/datastor.cpp | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/src/datastor.cpp b/src/datastor.cpp index c62edcb0a..a8f1a2740 100644 --- a/src/datastor.cpp +++ b/src/datastor.cpp @@ -44,8 +44,9 @@ Data_Store::search_with(const Matcher& matcher) const { std::multimap<std::string, std::string> out; - std::multimap<std::string, std::string>::const_iterator i; - i = contents.begin(); + std::multimap<std::string, std::string>::const_iterator i = + contents.begin(); + while(i != contents.end()) { if(matcher(i->first, i->second)) @@ -61,18 +62,13 @@ Data_Store::search_with(const Matcher& matcher) const *************************************************/ std::vector<std::string> Data_Store::get(const std::string& looking_for) const { - std::vector<std::string> out; + typedef std::multimap<std::string, std::string>::const_iterator iter; - // FIXME: use equal_range!!!! - std::multimap<std::string, std::string>::const_iterator i; - i = contents.begin(); - while(i != contents.end()) - { - if(i->first == looking_for) - out.push_back(i->second); - ++i; - } + std::pair<iter, iter> range = contents.equal_range(looking_for); + std::vector<std::string> out; + for(iter i = range.first; i != range.second; i++) + out.push_back(i->second); return out; } |