Configuration performance improvements and functionality enhancemens.#1452
Merged
jturner65 merged 5 commits intofacebookresearch:masterfrom Aug 26, 2021
Merged
Conversation
mosra
reviewed
Aug 26, 2021
src/esp/core/Configuration.h
Outdated
| const ConfigStoredType desiredType = configStoredTypeFor<T>(); | ||
| if (mapIter != valueMap_.end() && | ||
| (mapIter->second.getType() == desiredType)) { | ||
| return valueMap_.at(key).get<T>(); |
Contributor
There was a problem hiding this comment.
Suggested change
| return valueMap_.at(key).get<T>(); | |
| return mapIter->second.get<T>(); |
;)
src/esp/core/Configuration.h
Outdated
Comment on lines
370
to
371
| T val = valueMap_.at(key).get<T>(); | ||
| valueMap_.erase(key); |
Contributor
There was a problem hiding this comment.
Suggested change
| T val = valueMap_.at(key).get<T>(); | |
| valueMap_.erase(key); | |
| valueMap_.erase(mapIter); |
;)
Skylion007
approved these changes
Aug 26, 2021
f7c232a to
ba14fc3
Compare
mosra
approved these changes
Aug 26, 2021
Contributor
mosra
left a comment
There was a problem hiding this comment.
Looks good! One minor thing left.
| @@ -345,74 +365,65 @@ class Configuration { | |||
| // ****************** Value removal ****************** | |||
Contributor
There was a problem hiding this comment.
Did you add the float overload for set() or not? I think it could be a nice "annoyance removal" feature to avoid having to cast every other thing.
| bool hasSubconfig(const std::string& key) const { | ||
| return (configMap_.count(key) > 0); | ||
| ConfigMapType::const_iterator mapIter = configMap_.find(key); | ||
| return (mapIter != configMap_.end()); |
Contributor
There was a problem hiding this comment.
Here it could have stayed as the count(), i don't think STL is that stupid to look it up more than once :) But this consistent at least.
Contributor
Author
There was a problem hiding this comment.
I looked at the underlying code and find looked a bit quicker :D
template<typename _Key, typename _Value,
typename _Alloc, typename _ExtractKey, typename _Equal,
typename _H1, typename _H2, typename _Hash, typename _RehashPolicy,
typename _Traits>
auto
_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
_H1, _H2, _Hash, _RehashPolicy, _Traits>::
find(const key_type& __k) const
-> const_iterator
{
__hash_code __code = this->_M_hash_code(__k);
std::size_t __n = _M_bucket_index(__k, __code);
__node_type* __p = _M_find_node(__n, __k, __code);
return __p ? const_iterator(__p) : end();
}
template<typename _Key, typename _Value,
typename _Alloc, typename _ExtractKey, typename _Equal,
typename _H1, typename _H2, typename _Hash, typename _RehashPolicy,
typename _Traits>
auto
_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal,
_H1, _H2, _Hash, _RehashPolicy, _Traits>::
count(const key_type& __k) const
-> size_type
{
__hash_code __code = this->_M_hash_code(__k);
std::size_t __n = _M_bucket_index(__k, __code);
__node_type* __p = _M_bucket_begin(__n);
if (!__p)
return 0;
std::size_t __result = 0;
for (;; __p = __p->_M_next())
{
if (this->_M_equals(__k, __code, __p))
++__result;
else if (__result)
// All equivalent values are next to each other, if we
// found a non-equivalent value after an equivalent one it
// means that we won't find any new equivalent value.
break;
if (!__p->_M_nxt || _M_bucket_index(__p->_M_next()) != __n)
break;
}
return __result;
}
Contributor
Author
There was a problem hiding this comment.
(doesn't go through the entire bucket)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation and Context
This PR has some performance and functionality improvements/expansions for the Configurations, expanding upon the work of this PR..
How Has This Been Tested
Locally c++ and python
Types of changes
Checklist