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
|
public function keys () :Array
|
||||||
{
|
{
|
||||||
var keys :Array = [];
|
var keys :Array = [];
|
||||||
forEach(function (k :*, v :*) :void {
|
forEach0(function (k :*, v :*) :void {
|
||||||
keys.push(k);
|
keys.push(k);
|
||||||
});
|
});
|
||||||
return keys;
|
return keys;
|
||||||
@@ -226,7 +226,7 @@ public class HashMap
|
|||||||
public function values () :Array
|
public function values () :Array
|
||||||
{
|
{
|
||||||
var vals :Array = [];
|
var vals :Array = [];
|
||||||
forEach(function (k :*, v :*) :void {
|
forEach0(function (k :*, v :*) :void {
|
||||||
vals.push(v);
|
vals.push(v);
|
||||||
});
|
});
|
||||||
return vals;
|
return vals;
|
||||||
@@ -234,6 +234,15 @@ public class HashMap
|
|||||||
|
|
||||||
/** @inheritDoc */
|
/** @inheritDoc */
|
||||||
public function forEach (fn :Function) :void
|
public function forEach (fn :Function) :void
|
||||||
|
{
|
||||||
|
forEach0(fn);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal forEach.
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
protected function forEach0 (fn :Function) :void
|
||||||
{
|
{
|
||||||
if (_simpleData != null) {
|
if (_simpleData != null) {
|
||||||
for (var key :Object in _simpleData) {
|
for (var key :Object in _simpleData) {
|
||||||
|
|||||||
@@ -69,12 +69,10 @@ public class SortedHashMap extends HashMap
|
|||||||
|
|
||||||
override public function values () :Array
|
override public function values () :Array
|
||||||
{
|
{
|
||||||
var keys :Array = keys();
|
// not very optimal, we need to look up each value from the sorted keys.
|
||||||
var vals :Array = new Array();
|
return keys().map(function (key :Object, ... rest) :Object {
|
||||||
for each (var key :Object in keys) {
|
return get(key);
|
||||||
vals.push(get(key));
|
});
|
||||||
}
|
|
||||||
return vals;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override public function forEach (fn :Function) :void
|
override public function forEach (fn :Function) :void
|
||||||
|
|||||||
@@ -49,28 +49,19 @@ public class WeakValueHashMap extends HashMap
|
|||||||
/** @inheritDoc */
|
/** @inheritDoc */
|
||||||
override public function size () :int
|
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..
|
return super.size(); // alternately, we could prune and increment a count for all present..
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @inheritDoc */
|
/** @private */
|
||||||
override public function forEach (fn :Function) :void
|
override protected function forEach0 (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
|
|
||||||
{
|
{
|
||||||
var removeKeys :Array = [];
|
var removeKeys :Array = [];
|
||||||
super.forEach(function (key :*, value :WeakReference) :void {
|
super.forEach0(function (key :*, value :WeakReference) :void {
|
||||||
var rawVal :* = (value == null) ? null : value.get();
|
var rawVal :* = (value == null) ? null : value.get();
|
||||||
if (rawVal === undefined) {
|
if (rawVal === undefined) {
|
||||||
removeKeys.push(key);
|
removeKeys.push(key);
|
||||||
} else if (fn != null) {
|
} else {
|
||||||
fn(key, rawVal);
|
fn(key, rawVal);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -81,6 +72,7 @@ public class WeakValueHashMap extends HashMap
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Unwrap a possible WeakReference for returning to the user.
|
* Unwrap a possible WeakReference for returning to the user.
|
||||||
|
* @private
|
||||||
*/
|
*/
|
||||||
protected function unwrap (val :*) :*
|
protected function unwrap (val :*) :*
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user