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

Side by Side Diff: runtime/lib/expando_impl.dart

Issue 10872029: Quick fix for SDK after Expando addition in the VM. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 3 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/lib/expando.dart ('k') | runtime/lib/lib_sources.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 class _Expando<T> implements Expando<T> { 5 class _Expando<T> implements Expando<T> {
6 final String name; 6 final String name;
7 7
8 const _Expando([String this.name]); 8 const _Expando([String this.name]);
9 9
10 T operator[](Object object) { 10 T operator[](Object object) {
11 checkType(object); 11 checkType(object);
12 var weak_property = find(this); 12 var weakProperty = find(this);
13 var list = weak_property.value; 13 var list = weakProperty.value;
14 var do_compact = false; 14 var doCompact = false;
15 var result = null; 15 var result = null;
16 for (int i = 0; i < list.length; ++i) { 16 for (int i = 0; i < list.length; ++i) {
17 var key = list[i].key; 17 var key = list[i].key;
18 if (key === object) { 18 if (key === object) {
19 result = list[i].value; 19 result = list[i].value;
20 break; 20 break;
21 } 21 }
22 if (key === null) { 22 if (key === null) {
23 do_compact = true; 23 doCompact = true;
24 list[i] = null; 24 list[i] = null;
25 } 25 }
26 } 26 }
27 if (do_compact) { 27 if (doCompact) {
28 weak_property.value = list.filter((e) => (e !== null)); 28 weakProperty.value = list.filter((e) => (e !== null));
29 } 29 }
30 return result; 30 return result;
31 } 31 }
32 32
33 void operator[]=(Object object, T value) { 33 void operator[]=(Object object, T value) {
34 checkType(object); 34 checkType(object);
35 var weak_property = find(this); 35 var weakProperty = find(this);
36 var list = weak_property.value; 36 var list = weakProperty.value;
37 var do_compact = false; 37 var doCompact = false;
38 int i = 0; 38 int i = 0;
39 for (; i < list.length; ++i) { 39 for (; i < list.length; ++i) {
40 var key = list[i].key; 40 var key = list[i].key;
41 if (key === object) { 41 if (key === object) {
42 break; 42 break;
43 } 43 }
44 if (key === null) { 44 if (key === null) {
45 do_compact = true; 45 doCompact = true;
46 list[i] = null; 46 list[i] = null;
47 } 47 }
48 } 48 }
49 if (i !== list.length && value === null) { 49 if (i !== list.length && value === null) {
50 do_compact = true; 50 doCompact = true;
51 list[i] = null; 51 list[i] = null;
52 } else if (i !== list.length) { 52 } else if (i !== list.length) {
53 list[i].value = value; 53 list[i].value = value;
54 } else { 54 } else {
55 list.add(new _WeakProperty(object, value)); 55 list.add(new _WeakProperty(object, value));
56 } 56 }
57 if (do_compact) { 57 if (doCompact) {
58 weak_property.value = list.filter((e) => (e !== null)); 58 weakProperty.value = list.filter((e) => (e !== null));
59 } 59 }
60 } 60 }
61 61
62 String toString() => "Expando:$name"; 62 String toString() => "Expando:$name";
63 63
64 static checkType(object) { 64 static checkType(object) {
65 if (object === null) { 65 if (object === null) {
66 throw new NullPointerException(); 66 throw new NullPointerException();
67 } 67 }
68 if (object is bool || object is num || object is String) { 68 if (object is bool || object is num || object is String) {
69 throw new IllegalArgumentException(object); 69 throw new IllegalArgumentException(object);
70 } 70 }
71 } 71 }
72 72
73 static find(expando) { 73 static find(expando) {
74 if (data === null) data = new List(); 74 if (data === null) data = new List();
75 var do_compact = false; 75 var doCompact = false;
76 int i = 0; 76 int i = 0;
77 for (; i < data.length; ++i) { 77 for (; i < data.length; ++i) {
78 var key = data[i].key; 78 var key = data[i].key;
79 if (key == expando) { 79 if (key == expando) {
80 break; 80 break;
81 } 81 }
82 if (key === null) { 82 if (key === null) {
83 do_compact = true; 83 doCompact = true;
84 data[i] = null; 84 data[i] = null;
85 } 85 }
86 } 86 }
87 if (i == data.length) { 87 if (i == data.length) {
88 data.add(new _WeakProperty(expando, new List())); 88 data.add(new _WeakProperty(expando, new List()));
89 } 89 }
90 var result = data[i]; 90 var result = data[i];
91 if (do_compact) { 91 if (doCompact) {
92 data = data.filter((e) => (e !== null)); 92 data = data.filter((e) => (e !== null));
93 } 93 }
94 return result; 94 return result;
95 } 95 }
96 96
97 static List data; 97 static List data;
98 } 98 }
OLDNEW
« no previous file with comments | « runtime/lib/expando.dart ('k') | runtime/lib/lib_sources.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698