Skip to content

Commit

Permalink
Opimize operator[].
Browse files Browse the repository at this point in the history
  • Loading branch information
Tessil committed Jul 1, 2017
1 parent bc92979 commit 0468aca
Showing 1 changed file with 1 addition and 10 deletions.
11 changes: 1 addition & 10 deletions src/ordered_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -650,16 +650,7 @@ class ordered_hash: private Hash, private KeyEqual {

template<class K, class U = ValueSelect, typename std::enable_if<!std::is_same<U, void>::value>::type* = nullptr>
typename U::value_type& operator[](K&& key) {
// TODO Optimize
using T = typename U::value_type;

auto it = find(key);
if(it != end()) {
return it.value();
}
else {
return insert(std::make_pair(std::forward<K>(key), T())).first.value();
}
return insert_impl(std::forward<K>(key), hash_key(key)).first.value();
}

const_reference front() const {
Expand Down

0 comments on commit 0468aca

Please sign in to comment.