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

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

Issue 10909209: Eliminate the const constructor from the Expando class. (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 | « lib/core/expando.dart ('k') | tests/corelib/expando_test.dart » ('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 patch class Expando<T> { 5 patch class Expando<T> {
6 /* patch */ T operator[](Object object) { 6 /* patch */ T operator[](Object object) {
7 _checkType(object); 7 _checkType(object);
8 var weakProperty = _find(this);
9 var list = weakProperty.value;
10 var doCompact = false; 8 var doCompact = false;
11 var result = null; 9 var result = null;
12 for (int i = 0; i < list.length; ++i) { 10 if (_data !== null) {
hausner 2012/09/13 20:06:48 If you declare the constructor external and implem
cshapiro 2012/09/13 21:19:41 Good idea. Done.
13 var key = list[i].key; 11 for (int i = 0; i < _data.length; ++i) {
14 if (key === object) { 12 var key = _data[i].key;
15 result = list[i].value; 13 if (key === object) {
16 break; 14 result = _data[i].value;
15 break;
16 }
17 if (key === null) {
18 doCompact = true;
19 _data[i] = null;
20 }
17 } 21 }
18 if (key === null) { 22 if (doCompact) {
19 doCompact = true; 23 _data = _data.filter((e) => (e !== null));
20 list[i] = null;
21 } 24 }
22 } 25 }
23 if (doCompact) {
24 weakProperty.value = list.filter((e) => (e !== null));
25 }
26 return result; 26 return result;
27 } 27 }
28 28
29 /* patch */ void operator[]=(Object object, T value) { 29 /* patch */ void operator[]=(Object object, T value) {
30 _checkType(object); 30 _checkType(object);
31 var weakProperty = _find(this); 31 if (_data === null) _data = new List();
32 var list = weakProperty.value;
33 var doCompact = false; 32 var doCompact = false;
34 int i = 0; 33 int i = 0;
35 for (; i < list.length; ++i) { 34 for (; i < _data.length; ++i) {
36 var key = list[i].key; 35 var key = _data[i].key;
37 if (key === object) { 36 if (key === object) {
38 break; 37 break;
39 } 38 }
40 if (key === null) { 39 if (key === null) {
41 doCompact = true; 40 doCompact = true;
42 list[i] = null; 41 _data[i] = null;
43 } 42 }
44 } 43 }
45 if (i !== list.length && value === null) { 44 if (i !== _data.length && value === null) {
46 doCompact = true; 45 doCompact = true;
47 list[i] = null; 46 _data[i] = null;
48 } else if (i !== list.length) { 47 } else if (i !== _data.length) {
49 list[i].value = value; 48 _data[i].value = value;
50 } else { 49 } else {
51 list.add(new _WeakProperty(object, value)); 50 _data.add(new _WeakProperty(object, value));
52 } 51 }
53 if (doCompact) { 52 if (doCompact) {
54 weakProperty.value = list.filter((e) => (e !== null)); 53 _data = _data.filter((e) => (e !== null));
55 } 54 }
56 } 55 }
57 56
58 static _checkType(object) { 57 static _checkType(object) {
59 if (object === null) { 58 if (object === null) {
60 throw new NullPointerException(); 59 throw new NullPointerException();
61 } 60 }
62 if (object is bool || object is num || object is String) { 61 if (object is bool || object is num || object is String) {
63 throw new IllegalArgumentException(object); 62 throw new IllegalArgumentException(object);
64 } 63 }
65 } 64 }
66 65
67 static _find(expando) { 66 List _data;
68 if (_data === null) _data = new List();
69 var doCompact = false;
70 int i = 0;
71 for (; i < _data.length; ++i) {
72 var key = _data[i].key;
73 if (key == expando) {
74 break;
75 }
76 if (key === null) {
77 doCompact = true;
78 _data[i] = null;
79 }
80 }
81 if (i == _data.length) {
82 _data.add(new _WeakProperty(expando, new List()));
83 }
84 var result = _data[i];
85 if (doCompact) {
86 _data = _data.filter((e) => (e !== null));
87 }
88 return result;
89 }
90
91 static List _data;
92 } 67 }
OLDNEW
« no previous file with comments | « lib/core/expando.dart ('k') | tests/corelib/expando_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698