Should resolve infinite recursion with SortedHashMap.
Tip from the pros: when you change a class, you might want to check the subclasses for possible problems with that change. :P git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5729 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -216,7 +216,7 @@ public class HashMap
|
||||
public function keys () :Array
|
||||
{
|
||||
var keys :Array = [];
|
||||
forEach(function (k :*, v :*) :void {
|
||||
forEach0(function (k :*, v :*) :void {
|
||||
keys.push(k);
|
||||
});
|
||||
return keys;
|
||||
@@ -226,7 +226,7 @@ public class HashMap
|
||||
public function values () :Array
|
||||
{
|
||||
var vals :Array = [];
|
||||
forEach(function (k :*, v :*) :void {
|
||||
forEach0(function (k :*, v :*) :void {
|
||||
vals.push(v);
|
||||
});
|
||||
return vals;
|
||||
@@ -234,6 +234,15 @@ public class HashMap
|
||||
|
||||
/** @inheritDoc */
|
||||
public function forEach (fn :Function) :void
|
||||
{
|
||||
forEach0(fn);
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal forEach.
|
||||
* @private
|
||||
*/
|
||||
protected function forEach0 (fn :Function) :void
|
||||
{
|
||||
if (_simpleData != null) {
|
||||
for (var key :Object in _simpleData) {
|
||||
|
||||
@@ -69,12 +69,10 @@ public class SortedHashMap extends HashMap
|
||||
|
||||
override public function values () :Array
|
||||
{
|
||||
var keys :Array = keys();
|
||||
var vals :Array = new Array();
|
||||
for each (var key :Object in keys) {
|
||||
vals.push(get(key));
|
||||
}
|
||||
return vals;
|
||||
// not very optimal, we need to look up each value from the sorted keys.
|
||||
return keys().map(function (key :Object, ... rest) :Object {
|
||||
return get(key);
|
||||
});
|
||||
}
|
||||
|
||||
override public function forEach (fn :Function) :void
|
||||
|
||||
@@ -49,28 +49,19 @@ public class WeakValueHashMap extends HashMap
|
||||
/** @inheritDoc */
|
||||
override public function size () :int
|
||||
{
|
||||
prune();
|
||||
forEach0(function (k :*, v: *) :void {});
|
||||
return super.size(); // alternately, we could prune and increment a count for all present..
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
override public function forEach (fn :Function) :void
|
||||
{
|
||||
prune(fn); // just prune & run the forEach at the same time
|
||||
}
|
||||
|
||||
/**
|
||||
* Prune garbage collected values from the map, optionally calling a function for each
|
||||
* found key/value pair.
|
||||
*/
|
||||
protected function prune (fn :Function = null) :void
|
||||
/** @private */
|
||||
override protected function forEach0 (fn :Function) :void
|
||||
{
|
||||
var removeKeys :Array = [];
|
||||
super.forEach(function (key :*, value :WeakReference) :void {
|
||||
super.forEach0(function (key :*, value :WeakReference) :void {
|
||||
var rawVal :* = (value == null) ? null : value.get();
|
||||
if (rawVal === undefined) {
|
||||
removeKeys.push(key);
|
||||
} else if (fn != null) {
|
||||
} else {
|
||||
fn(key, rawVal);
|
||||
}
|
||||
});
|
||||
@@ -81,6 +72,7 @@ public class WeakValueHashMap extends HashMap
|
||||
|
||||
/**
|
||||
* Unwrap a possible WeakReference for returning to the user.
|
||||
* @private
|
||||
*/
|
||||
protected function unwrap (val :*) :*
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user