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

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

Issue 10870064: Use patching for Expando so the implementation-specific files are not needed in the SDK. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Adding missing file 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
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 patch class ExpandoImplementation<T> {
6 final String name; 6 /* patch */ T operator[](Object object) {
7 7 _checkType(object);
8 const _Expando([String this.name]); 8 var weakProperty = _find(this);
9
10 T operator[](Object object) {
11 checkType(object);
12 var weakProperty = find(this);
13 var list = weakProperty.value; 9 var list = weakProperty.value;
14 var doCompact = false; 10 var doCompact = false;
15 var result = null; 11 var result = null;
16 for (int i = 0; i < list.length; ++i) { 12 for (int i = 0; i < list.length; ++i) {
17 var key = list[i].key; 13 var key = list[i].key;
18 if (key === object) { 14 if (key === object) {
19 result = list[i].value; 15 result = list[i].value;
20 break; 16 break;
21 } 17 }
22 if (key === null) { 18 if (key === null) {
23 doCompact = true; 19 doCompact = true;
24 list[i] = null; 20 list[i] = null;
25 } 21 }
26 } 22 }
27 if (doCompact) { 23 if (doCompact) {
28 weakProperty.value = list.filter((e) => (e !== null)); 24 weakProperty.value = list.filter((e) => (e !== null));
29 } 25 }
30 return result; 26 return result;
31 } 27 }
32 28
33 void operator[]=(Object object, T value) { 29 /* patch */ void operator[]=(Object object, T value) {
34 checkType(object); 30 _checkType(object);
35 var weakProperty = find(this); 31 var weakProperty = _find(this);
36 var list = weakProperty.value; 32 var list = weakProperty.value;
37 var doCompact = false; 33 var doCompact = false;
38 int i = 0; 34 int i = 0;
39 for (; i < list.length; ++i) { 35 for (; i < list.length; ++i) {
40 var key = list[i].key; 36 var key = list[i].key;
41 if (key === object) { 37 if (key === object) {
42 break; 38 break;
43 } 39 }
44 if (key === null) { 40 if (key === null) {
45 doCompact = true; 41 doCompact = true;
46 list[i] = null; 42 list[i] = null;
47 } 43 }
48 } 44 }
49 if (i !== list.length && value === null) { 45 if (i !== list.length && value === null) {
50 doCompact = true; 46 doCompact = true;
51 list[i] = null; 47 list[i] = null;
52 } else if (i !== list.length) { 48 } else if (i !== list.length) {
53 list[i].value = value; 49 list[i].value = value;
54 } else { 50 } else {
55 list.add(new _WeakProperty(object, value)); 51 list.add(new _WeakProperty(object, value));
56 } 52 }
57 if (doCompact) { 53 if (doCompact) {
58 weakProperty.value = list.filter((e) => (e !== null)); 54 weakProperty.value = list.filter((e) => (e !== null));
59 } 55 }
60 } 56 }
61 57
62 String toString() => "Expando:$name"; 58 static _checkType(object) {
63
64 static checkType(object) {
65 if (object === null) { 59 if (object === null) {
66 throw new NullPointerException(); 60 throw new NullPointerException();
67 } 61 }
68 if (object is bool || object is num || object is String) { 62 if (object is bool || object is num || object is String) {
69 throw new IllegalArgumentException(object); 63 throw new IllegalArgumentException(object);
70 } 64 }
71 } 65 }
72 66
73 static find(expando) { 67 static _find(expando) {
74 if (data === null) data = new List(); 68 if (_data === null) _data = new List();
75 var doCompact = false; 69 var doCompact = false;
76 int i = 0; 70 int i = 0;
77 for (; i < data.length; ++i) { 71 for (; i < _data.length; ++i) {
78 var key = data[i].key; 72 var key = _data[i].key;
79 if (key == expando) { 73 if (key == expando) {
80 break; 74 break;
81 } 75 }
82 if (key === null) { 76 if (key === null) {
83 doCompact = true; 77 doCompact = true;
84 data[i] = null; 78 _data[i] = null;
85 } 79 }
86 } 80 }
87 if (i == data.length) { 81 if (i == _data.length) {
88 data.add(new _WeakProperty(expando, new List())); 82 _data.add(new _WeakProperty(expando, new List()));
89 } 83 }
90 var result = data[i]; 84 var result = _data[i];
91 if (doCompact) { 85 if (doCompact) {
92 data = data.filter((e) => (e !== null)); 86 _data = _data.filter((e) => (e !== null));
93 } 87 }
94 return result; 88 return result;
95 } 89 }
96 90
97 static List data; 91 static List _data;
98 } 92 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698