Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(368)

Unified Diff: runtime/vm/growable_array.h

Issue 1312833009: Added {Zone}GrowableHandlePtrArray types: simplifies code, makes code safer (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/class_finalizer.cc ('k') | runtime/vm/growable_array_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/growable_array.h
diff --git a/runtime/vm/growable_array.h b/runtime/vm/growable_array.h
index 1e7c2041f8a86d94429ec8260821fd51ea3c1d11..88163fbb1f5ab5b1a424be5d63f3fc996d419250 100644
--- a/runtime/vm/growable_array.h
+++ b/runtime/vm/growable_array.h
@@ -195,6 +195,57 @@ class ZoneGrowableArray : public BaseGrowableArray<T, ZoneAllocated> {
};
+// T must be a Handle type.
+template<typename T, typename B>
+class BaseGrowableHandlePtrArray : public B {
+ public:
+ BaseGrowableHandlePtrArray(Zone* zone, intptr_t initial_capacity)
+ : zone_(zone), array_(zone, initial_capacity) {}
+
+ // Use unique zone handles to store objects.
Florian Schneider 2015/08/31 07:02:59 Why do the handles need to be unique? I think you
srdjan 2015/08/31 14:52:40 Often, e.g., in a loop, we reuse the handles. This
+ void Add(const T& t) {
+ array_.Add(&T::ZoneHandle(zone_, t.raw()));
+ }
+
+ T& operator[](intptr_t index) const {
+ return *array_[index];
+ }
+
+ const T& At(intptr_t index) const {
+ return operator[](index);
+ }
+
+ intptr_t length() const { return array_.length(); }
+
+ const GrowableArray<T*>& growable_array() const { return array_; }
+
+ private:
+ Zone* zone_;
+ GrowableArray<T*> array_;
+
+ DISALLOW_COPY_AND_ASSIGN(BaseGrowableHandlePtrArray);
+};
+
+
+template<typename T>
+class GrowableHandlePtrArray :
+ public BaseGrowableHandlePtrArray<T, ValueObject> {
+ public:
+ GrowableHandlePtrArray(Zone* zone, intptr_t initial_capacity)
+ : BaseGrowableHandlePtrArray<T, ValueObject>(zone, initial_capacity) {}
+};
+
+
+template<typename T>
+class ZoneGrowableHandlePtrArray :
+ public BaseGrowableHandlePtrArray<T, ZoneAllocated> {
+ public:
+ ZoneGrowableHandlePtrArray(Zone* zone, intptr_t initial_capacity)
+ : BaseGrowableHandlePtrArray<T, ZoneAllocated>(zone, initial_capacity) {}
+};
+
+
+
class Malloc : public AllStatic {
public:
template <class T>
« no previous file with comments | « runtime/vm/class_finalizer.cc ('k') | runtime/vm/growable_array_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698