forked from richardlord/Ash
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add object pool for reusing node objects.
- Loading branch information
1 parent
5b8749f
commit b0143e3
Showing
6 changed files
with
139 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package net.richardlord.ash.core | ||
{ | ||
internal class NodePool | ||
{ | ||
private var tail : Node; | ||
private var nodeClass : Class; | ||
private var cacheTail : Node; | ||
|
||
public function NodePool( nodeClass : Class ) | ||
{ | ||
this.nodeClass = nodeClass; | ||
} | ||
|
||
internal function get() : Node | ||
{ | ||
if ( tail ) | ||
{ | ||
var node : Node = tail; | ||
tail = tail.previous; | ||
node.previous = null; | ||
return node; | ||
} | ||
else | ||
{ | ||
return new nodeClass(); | ||
} | ||
} | ||
|
||
internal function dispose( node : Node ) : void | ||
{ | ||
node.next = null; | ||
node.previous = tail; | ||
tail = node; | ||
} | ||
|
||
internal function cache( node : Node ) : void | ||
{ | ||
node.previous = cacheTail; | ||
cacheTail = node; | ||
} | ||
|
||
internal function releaseCache() : void | ||
{ | ||
while( cacheTail ) | ||
{ | ||
var node : Node = cacheTail; | ||
cacheTail = node.previous; | ||
node.next = null; | ||
node.previous = tail; | ||
tail = node; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package net.richardlord.ash.signals | ||
{ | ||
internal class ListenerNodePool | ||
{ | ||
private var tail : ListenerNode; | ||
private var cacheTail : ListenerNode; | ||
|
||
internal function get():ListenerNode | ||
{ | ||
if( tail ) | ||
{ | ||
var node : ListenerNode = tail; | ||
tail = tail.previous; | ||
node.previous = null; | ||
return node; | ||
} | ||
else | ||
{ | ||
return new ListenerNode(); | ||
} | ||
} | ||
|
||
internal function dispose( node : ListenerNode ):void | ||
{ | ||
node.next = null; | ||
node.previous = tail; | ||
tail = node; | ||
} | ||
|
||
internal function cache( node : ListenerNode ) : void | ||
{ | ||
node.previous = cacheTail; | ||
cacheTail = node; | ||
} | ||
|
||
internal function releaseCache() : void | ||
{ | ||
while( cacheTail ) | ||
{ | ||
var node : ListenerNode = cacheTail; | ||
cacheTail = node.previous; | ||
node.next = null; | ||
node.previous = tail; | ||
tail = node; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters