From a9bbc08daad6d601c870c8493323f57b70373336 Mon Sep 17 00:00:00 2001 From: Alex Light Date: Thu, 14 Nov 2019 14:51:41 -0800 Subject: Implement STL iterators on ObjectArray and add helpers Iterating over an ObjectArray is rather cumbersome, requiring manual for-loops. To improve ergonomics and STL standard-ness this implements std::iterator's for ObjectArray and converts code to use this (in simple situations). This should allow us to use standard STL functions in the future when dealing with ObjectArrays. Also adds some helpers such as ZipCount and ZipLeft. Test: ./test.py --host Change-Id: Ifd515b8321775424b3256a6faf47b2ba970177d3 --- runtime/class_loader_utils.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'runtime/class_loader_utils.h') diff --git a/runtime/class_loader_utils.h b/runtime/class_loader_utils.h index 2e8504391a..1c353604fa 100644 --- a/runtime/class_loader_utils.h +++ b/runtime/class_loader_utils.h @@ -23,6 +23,7 @@ #include "jni/jni_internal.h" #include "mirror/class_loader.h" #include "mirror/object-inl.h" +#include "mirror/object.h" #include "native/dalvik_system_DexFile.h" #include "scoped_thread_state_change-inl.h" #include "well_known_classes.h" @@ -86,8 +87,7 @@ inline RetType VisitClassLoaderDexElements(ScopedObjectAccessAlreadyRunnable& so StackHandleScope<1> hs(self); Handle> dex_elements = hs.NewHandle(dex_elements_obj->AsObjectArray()); - for (int32_t i = 0; i < dex_elements->GetLength(); ++i) { - ObjPtr element = dex_elements->GetWithoutChecks(i); + for (auto element : dex_elements.Iterate()) { if (element == nullptr) { // Should never happen, fail. break; -- cgit v1.2.3-59-g8ed1b