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

Unified Diff: runtime/vm/object.h

Issue 1150103005: Provide a logical view of VM-internal maps in Observatory. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 7 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
Index: runtime/vm/object.h
diff --git a/runtime/vm/object.h b/runtime/vm/object.h
index 39a57ba80d8ff26963d8dbc03075a943054417e9..a93b1814f0b775ed1e32636a286d8e265926bc13 100644
--- a/runtime/vm/object.h
+++ b/runtime/vm/object.h
@@ -7233,6 +7233,52 @@ class LinkedHashMap : public Instance {
return OFFSET_OF(RawLinkedHashMap, deleted_keys_);
}
+ intptr_t Length() const {
+ intptr_t used = Smi::Value(raw_ptr()->used_data_);
+ intptr_t deleted = Smi::Value(raw_ptr()->deleted_keys_);
+ return (used >> 1) - deleted;
+ }
+
+ class Iterator : ValueObject {
koda 2015/06/02 16:42:37 Add comment to note how this differs from its Dart
rmacnak 2015/06/02 17:33:31 Done.
+ public:
+ explicit Iterator(const LinkedHashMap& map)
+ : map_(map)
+ , data_(Array::Handle(map.data()))
koda 2015/06/02 16:42:37 I think our code usually has these commas at the e
rmacnak 2015/06/02 17:33:31 Ah, yes. Before is Blink.
+ , scratch_(Object::Handle())
+ , offset_(-2)
+ , length_(Smi::Handle(map.used_data()).Value()) {}
koda 2015/06/02 16:42:37 Avoid handle creation: Smi::Value(map.used_data())
rmacnak 2015/06/02 17:33:31 Done.
+
+ bool MoveNext() {
+ // Cf. _CompactIterator in runtime/lib/compact_hash.dart.
+ while (true) {
+ offset_ += 2;
+ if (offset_ >= length_) {
+ return false;
+ }
+ scratch_ = data_.At(offset_);
+ if (scratch_.raw() != data_.raw()) {
+ // Slot is not deleted (self-reference indicates deletion).
+ return true;
+ }
+ }
+ }
+
+ RawObject* CurrentKey() const {
+ return data_.At(offset_);
+ }
+
+ RawObject* CurrentValue() const {
+ return data_.At(offset_ + 1);
+ }
+
+ private:
+ const LinkedHashMap& map_;
+ const Array& data_;
+ Object& scratch_;
+ intptr_t offset_;
+ const intptr_t length_;
+ };
+
private:
FINAL_HEAP_OBJECT_IMPLEMENTATION(LinkedHashMap, Instance);

Powered by Google App Engine
This is Rietveld 408576698