diff options
author | 2020-11-12 17:05:28 +0000 | |
---|---|---|
committer | 2020-11-13 10:07:21 +0000 | |
commit | b6837f0350ff66c13582b0e94178dd5ca283ff0a (patch) | |
tree | f79fff81352545efe967850e3d17e32255dcfecd /libartbase/base/stl_util.h | |
parent | 32c2eb81320f24b5bab24754204b8be95faa08b0 (diff) |
Revert^2 "Partial LSE analysis & store removal"
A ScopedArenaAllocator in a single test was accidentally loaded using
operator new which is not supported. This caused a memory leak.
This reverts commit fe270426c8a2a69a8f669339e83b86fbf40e25a1.
This unreverts commit bb6cda60e4418c0ab557ea4090e046bed8206763.
Bug: 67037140
Reason for revert: Fixed memory leak in
LoadStoreAnalysisTest.PartialEscape test case
Test: SANITIZE_HOST=address ASAN_OPTIONS=detect_leaks=0 m test-art-host-gtest-dependencies
Run art_compiler_tests
Change-Id: I34fa2079df946ae54b8c91fa771a44d56438a719
Diffstat (limited to 'libartbase/base/stl_util.h')
-rw-r--r-- | libartbase/base/stl_util.h | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/libartbase/base/stl_util.h b/libartbase/base/stl_util.h index cd7b812b72..503dfee1d6 100644 --- a/libartbase/base/stl_util.h +++ b/libartbase/base/stl_util.h @@ -229,6 +229,64 @@ static inline IterationRange<ZipLeftIter<IterLeft, IterRight>> ZipLeft( ZipLeftIter(iter_left.end(), iter_right.end())); } +static inline IterationRange<CountIter> Range(size_t start, size_t end) { + return IterationRange(CountIter(start), CountIter(end)); +} + +static inline IterationRange<CountIter> Range(size_t end) { + return Range(0, end); +} + +template <typename RealIter, typename Filter> +struct FilterIterator + : public std::iterator<std::forward_iterator_tag, typename RealIter::value_type> { + public: + FilterIterator(RealIter rl, + Filter cond, + std::optional<RealIter> end = std::nullopt) + : real_iter_(rl), cond_(cond), end_(end) { + DCHECK(std::make_optional(rl) == end_ || cond_(*real_iter_)); + } + + FilterIterator<RealIter, Filter>& operator++() { + DCHECK(std::make_optional(real_iter_) != end_); + do { + if (std::make_optional(++real_iter_) == end_) { + break; + } + } while (!cond_(*real_iter_)); + return *this; + } + FilterIterator<RealIter, Filter> operator++(int) { + FilterIterator<RealIter, Filter> ret(real_iter_, cond_, end_); + ++(*this); + return ret; + } + bool operator==(const FilterIterator<RealIter, Filter>& other) const { + return real_iter_ == other.real_iter_; + } + bool operator!=(const FilterIterator<RealIter, Filter>& other) const { + return !(*this == other); + } + typename RealIter::value_type operator*() const { + return *real_iter_; + } + + private: + RealIter real_iter_; + Filter cond_; + std::optional<RealIter> end_; +}; + +template <typename Iter, typename Filter> +static inline IterationRange<FilterIterator<Iter, Filter>> Filter( + IterationRange<Iter> it, Filter cond) { + auto end = it.end(); + auto start = std::find_if(it.begin(), end, cond); + return MakeIterationRange(FilterIterator(start, cond, std::make_optional(end)), + FilterIterator(end, cond, std::make_optional(end))); +} + } // namespace art #endif // ART_LIBARTBASE_BASE_STL_UTIL_H_ |