summaryrefslogtreecommitdiffstats
path: root/runtime/mirror/array-inl.h
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/mirror/array-inl.h')
-rw-r--r--runtime/mirror/array-inl.h24
1 files changed, 16 insertions, 8 deletions
diff --git a/runtime/mirror/array-inl.h b/runtime/mirror/array-inl.h
index 2955faa..46ffaae 100644
--- a/runtime/mirror/array-inl.h
+++ b/runtime/mirror/array-inl.h
@@ -58,13 +58,20 @@ static inline size_t ComputeArraySize(Thread* self, Class* array_class, int32_t
return size;
}
-static inline Array* SetArrayLength(Array* array, size_t length) {
- if (LIKELY(array != nullptr)) {
+class SetLengthVisitor {
+ public:
+ explicit SetLengthVisitor(int32_t length) : length_(length) {
+ }
+
+ void operator()(mirror::Object* obj) const {
+ mirror::Array* array = obj->AsArray();
DCHECK(array->IsArrayInstance());
- array->SetLength(length);
+ array->SetLength(length_);
}
- return array;
-}
+
+ private:
+ const int32_t length_;
+};
template <bool kIsInstrumented>
inline Array* Array::Alloc(Thread* self, Class* array_class, int32_t component_count,
@@ -74,9 +81,10 @@ inline Array* Array::Alloc(Thread* self, Class* array_class, int32_t component_c
return nullptr;
}
gc::Heap* heap = Runtime::Current()->GetHeap();
- Array* array = down_cast<Array*>(
- heap->AllocObjectWithAllocator<kIsInstrumented>(self, array_class, size, allocator_type));
- return SetArrayLength(array, component_count);
+ SetLengthVisitor visitor(component_count);
+ return down_cast<Array*>(
+ heap->AllocObjectWithAllocator<kIsInstrumented>(self, array_class, size, allocator_type,
+ visitor));
}
template <bool kIsInstrumented>