Cached data for oi::SizedResult
is stored in the short lived iterator
#479
Labels
oi::SizedResult
is stored in the short lived iterator
#479
SizedResult
uses a two pass algorithm to provide total size for every element when iterating anoi::IntrospectionResult
. In the first pass it fills up astd::vector<SizeHelper>
to make the calculation of size trivial. In the second pass it returns theoi::result::Element
from theoi::IntrospectionResult::const_iterator
with the calculated size to return anoi::result::SizedResult
.The current approach stores the
std::vector<SizeHelper>
in theconst_iterator
and fills it when theconst_iterator
is constructed. Filling the vector when the iterator is constructed makes sense as it delays the work until it is used. The downside of this approach is if you create twoconst_iterator
s for theoi::SizedResult
(a natural way to use it) you do this work twice.For example
It would be relatively simple to store this
std::vector<SizeHelper>
in theSizedResult
and store a reference to it in theSizedResult::const_iterator
. When creating aconst_iterator
you would check if the cache vector is empty, and if so attempt to fill it. Then theSizedResult::const_iterator
could hold astd::span<const SizeHelper>
to this vector instead of owning it. Future iterators would not need to redo this work. As the underlying result is unchanged and traversing it is deterministic there's no problem with this caching.The text was updated successfully, but these errors were encountered: