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

Unified Diff: runtime/lib/expando.dart

Issue 10861041: Provide an Expando implementation for the VM. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: add missing whitespace Created 8 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 | « corelib/src/corelib_sources.gypi ('k') | runtime/lib/lib_impl_sources.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/expando.dart
diff --git a/runtime/lib/expando.dart b/runtime/lib/expando.dart
new file mode 100644
index 0000000000000000000000000000000000000000..fdfc0a72cf4b0d87374b7ea3bdc8215841fd37bd
--- /dev/null
+++ b/runtime/lib/expando.dart
@@ -0,0 +1,107 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+class _Expando<T> implements Expando<T> {
+ final String name;
+
+ const _Expando([String this.name]);
+
+ T operator[](Object object) {
+ checkType(object);
+ var weak_property = find(this);
+ var do_compact = false;
+ var result = null;
+ var list = weak_property.value;
+ for (int i = 0; i < list.length; ++i) {
+ if (list[i] !== null) {
Ivan Posva 2012/08/21 23:19:40 How can this ever be false?
cshapiro 2012/08/22 02:37:35 This was needed before I added compaction. Since
+ var key = list[i].key;
+ if (key === object) {
+ result = list[i].value;
+ break;
+ }
+ if (key === null) {
+ do_compact = true;
+ list[i] = null;
+ }
+ }
+ }
+ if (do_compact) {
+ weak_property.value = list.filter((e) => (e === null));
+ }
+ return result;
+ }
+
+ void operator[]=(Object object, T value) {
+ checkType(object);
+ var weak_property = find(this);
+ var do_compact = false;
+ var list = weak_property.value;
+ int i = 0;
+ for (; i < list.length; ++i) {
+ if (list[i] !== null) {
+ var key = list[i].key;
+ if (key === object) {
+ break;
+ }
+ if (key === null) {
+ do_compact = true;
+ list[i] = null;
+ }
+ }
+ }
+ if (i !== list.length && value === null) {
+ do_compact = true;
+ list[i] = null;
+ } else {
+ var weak_property = new WeakProperty(object, value);
Ivan Posva 2012/08/21 23:19:40 It is confusing to be shadowing the outer weak_pro
cshapiro 2012/08/22 02:37:35 I removed this as part of an unrelated simplificat
+ if (i !== list.length) {
+ list[i] = weak_property;
Ivan Posva 2012/08/21 23:19:40 Why not "list[i].value = value"?
cshapiro 2012/08/22 02:37:35 While I added a setter for the value field, my pre
+ } else {
+ list.add(weak_property);
+ }
+ }
+ if (do_compact) {
+ weak_property.value = list.filter((e) => (e === null));
+ }
+ }
+
+ String toString() => "Expando:$name";
+
+ static checkType(object) {
+ if (object === null) {
+ throw new NullPointerException();
+ }
+ if (object is bool || object is num || object is String) {
+ throw new IllegalArgumentException(object);
+ }
+ }
+
+ static find(expando) {
+ if (data === null) data = new List();
+ var do_compact = false;
+ int i = 0;
+ for (; i < data.length; ++i) {
+ if (data[i] !== null) {
+ var key = data[i].key;
+ if (key == expando) {
+ break;
+ }
+ if (key === null) {
+ do_compact = true;
+ data[i] = null;
+ }
+ }
+ }
+ if (i == data.length) {
+ data.add(new WeakProperty(expando, new List()));
+ }
+ var result = data[i];
+ if (do_compact) {
+ data = data.filter((e) => (e === null));
+ }
+ return result;
+ }
+
+ static List data;
+}
« no previous file with comments | « corelib/src/corelib_sources.gypi ('k') | runtime/lib/lib_impl_sources.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698