Files
sdk/runtime/lib/expando_patch.dart
T
hausner@google.com bf5835d89e BREAKING CHANGE: Remove === and !== in the VM compiler
This change is long overdue. Fixed the last places where we
still used ===.

R=iposva@google.com

Review URL: https://codereview.chromium.org//16398006

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@23751 260f80e4-7a28-3924-810f-c04153c831b5
2013-06-07 16:31:33 +00:00

64 lines
1.6 KiB
Dart

// 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.
patch class Expando<T> {
/* patch */ Expando([this.name]) : _data = new List();
/* patch */ T operator[](Object object) {
_checkType(object);
var doCompact = false;
var result = null;
for (int i = 0; i < _data.length; ++i) {
var key = _data[i].key;
if (identical(key, object)) {
result = _data[i].value;
break;
}
if (key == null) {
doCompact = true;
_data[i] = null;
}
}
if (doCompact) {
_data = _data.where((e) => (e != null)).toList();
}
return result;
}
/* patch */ void operator[]=(Object object, T value) {
_checkType(object);
var doCompact = false;
int i = 0;
for (; i < _data.length; ++i) {
var key = _data[i].key;
if (identical(key, object)) {
break;
}
if (key == null) {
doCompact = true;
_data[i] = null;
}
}
if (i != _data.length && value == null) {
doCompact = true;
_data[i] = null;
} else if (i != _data.length) {
_data[i].value = value;
} else {
_data.add(new _WeakProperty(object, value));
}
if (doCompact) {
_data = _data.where((e) => (e != null)).toList();
}
}
static _checkType(object) {
if (object == null || object is bool || object is num || object is String) {
throw new ArgumentError(object);
}
}
List _data;
}