Looking at DBFieldLength.h for #119, I starting looking into when to use constexpr, which led me here, then here.
My personal recommendation is to avoid the [] operator. If you want to use an entry if it exists, then use map::find().
auto item = m.find(2);
if (item != m.end()) {
DoSomethingWith(*item);
}
Reminded me that a lot of the time I compare the result of std::unordered_map::find to std::unordered_map::end ignore it when I could be saving it to a variable, and then waste time doing a lookup again later, usually with std::unordered_map::at.
That article led me to this video. Neato. I'd noticed the behavior the presenter describes, but avoided it due to the same "newbie" expectations he cites, of uninitialized rather than value-initialized doubles. Thought it was possible that not every C++ compiler would gimme the results I was seeing. Great news. This could mean good things for compute_stats_t.
Finally, the first of thesetwo StackOverflow threads leads right back to Louis Brandy's video.
There are several ways to better use std::unordered map:
catch
Consider using std::unordered_map::find, comparing to std::unordered_map::end and dereferencing the result instead of (potentially expensively?) constructing std::out_of_range objects.
count
Consider using std::unordered_map::find and dereferencing the result instead of discarding it and searching again with std::unordered_map::at or whatever
All there is right now, at least in the master branch, is 9e2e4ef.
all occurrences
[] may be accompanied by other unnecessary operations
.find cases can often have results saved in a variable
insert and emplace may benefit from better use of their respective construction methods; try piecewise-construct
...and whatever else
Looking at DBFieldLength.h for #119, I starting looking into when to use constexpr, which led me here, then here.
Reminded me that a lot of the time I compare the result of
std::unordered_map::findtostd::unordered_map::endignore it when I could be saving it to a variable, and then waste time doing a lookup again later, usually withstd::unordered_map::at.That article led me to this video. Neato. I'd noticed the behavior the presenter describes, but avoided it due to the same "newbie" expectations he cites, of uninitialized rather than value-initialized
doubles. Thought it was possible that not every C++ compiler would gimme the results I was seeing. Great news. This could mean good things forcompute_stats_t.Finally, the first of thesetwo StackOverflow threads leads right back to Louis Brandy's video.
There are several ways to better use
std::unordered map:catch
Consider using
std::unordered_map::find, comparing tostd::unordered_map::endand dereferencing the result instead of (potentially expensively?) constructingstd::out_of_rangeobjects.[] +=[] +=count
Consider using
std::unordered_map::findand dereferencing the result instead of discarding it and searching again withstd::unordered_map::ator whateverAll there is right now, at least in the master branch, is 9e2e4ef.
active_only_mileage_by_region.find(region)as an iteratorsystem_region_milesworks (and all occurrences) -- does/can it just return 0?all occurrences
[]may be accompanied by other unnecessary operations.findcases can often have results saved in a variableinsertandemplacemay benefit from better use of their respective construction methods; try piecewise-construct...and whatever else