Permalink
Browse files

Reimplement registerDisposable in term of on-dispose callback.

Presumably, unless you're creating and disposing object in hot loop
(if you do that, you should probably fix that anyway),
slight loss in performance should not matter (I'm not even sure this
will actually be slower, given that goog.disposeAll creates an
arguments object).

R=nnaze
DELTA=15 (0 added, 14 deleted, 1 changed)


Revision created by MOE tool push_codebase.
MOE_MIGRATION=6180


git-svn-id: http://closure-library.googlecode.com/svn/trunk@2459 0b95b8e8-c90f-11de-9d4f-f947ee5921c8
  • Loading branch information...
1 parent 5764243 commit 752adffb35b0cf4f39c013b00c773c7c391678a7 chrishenry@google.com committed Jan 23, 2013
Showing with 1 addition and 15 deletions.
  1. +1 −15 closure/goog/disposable/disposable.js
@@ -117,14 +117,6 @@ goog.Disposable.prototype.disposed_ = false;
/**
- * Disposables that should be disposed when this object is disposed.
- * @type {Array.<goog.disposable.IDisposable>}
- * @private
- */
-goog.Disposable.prototype.dependentDisposables_;
-
-
-/**
* Callbacks to invoke when this object is disposed.
* @type {Array.<!Function>}
* @private
@@ -193,10 +185,7 @@ goog.Disposable.prototype.dispose = function() {
* this object is disposed.
*/
goog.Disposable.prototype.registerDisposable = function(disposable) {
- if (!this.dependentDisposables_) {
- this.dependentDisposables_ = [];
- }
- this.dependentDisposables_.push(disposable);
+ this.addOnDisposeCallback(goog.partial(goog.dispose, disposable));
};
@@ -242,9 +231,6 @@ goog.Disposable.prototype.addOnDisposeCallback = function(callback, opt_scope) {
* @protected
*/
goog.Disposable.prototype.disposeInternal = function() {
- if (this.dependentDisposables_) {
- goog.disposeAll.apply(null, this.dependentDisposables_);
- }
if (this.onDisposeCallbacks_) {
while (this.onDisposeCallbacks_.length) {
this.onDisposeCallbacks_.shift()();

0 comments on commit 752adff

Please sign in to comment.