Skip to content

Commit

Permalink
Remove PooledClass from TopLevelCallbackBookKeeping
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon Dail committed Jul 21, 2017
1 parent 011e37f commit d9f717d
Showing 1 changed file with 29 additions and 20 deletions.
49 changes: 29 additions & 20 deletions src/renderers/dom/shared/ReactDOMEventListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
'use strict';

var EventListener = require('fbjs/lib/EventListener');
var PooledClass = require('PooledClass');
var ReactDOMComponentTree = require('ReactDOMComponentTree');
var ReactFiberTreeReflection = require('ReactFiberTreeReflection');
var ReactGenericBatching = require('ReactGenericBatching');
Expand All @@ -22,6 +21,9 @@ var getEventTarget = require('getEventTarget');

var {HostRoot} = ReactTypeOfWork;

var CALLBACK_BOOKKEEPING_POOL_SIZE = 10;
var callbackBookkeepingPool = [];

/**
* Find the deepest React component completely containing the root of the
* passed-in instance (for use when entire React trees are nested within each
Expand Down Expand Up @@ -50,24 +52,31 @@ function findRootContainerNode(inst) {
}

// Used to store ancestor hierarchy in top level callback
function TopLevelCallbackBookKeeping(topLevelType, nativeEvent, targetInst) {
this.topLevelType = topLevelType;
this.nativeEvent = nativeEvent;
this.targetInst = targetInst;
this.ancestors = [];
function getTopLevelCallbackBookKeeping(topLevelType, nativeEvent, targetInst) {
if (callbackBookkeepingPool.length) {
const instance = callbackBookkeepingPool.pop();
instance.topLevelType = topLevelType;
instance.nativeEvent = nativeEvent;
instance.targetInst = targetInst;
return instance;
}
return {
topLevelType,
nativeEvent,
targetInst,
ancestors: [],
};
}

function releaseTopLevelCallbackBookKeeping(instance) {
instance.topLevelType = null;
instance.nativeEvent = null;
instance.targetInst = null;
instance.ancestors.length = 0;
if (callbackBookkeepingPool.length < CALLBACK_BOOKKEEPING_POOL_SIZE) {
callbackBookkeepingPool.push(instance);
}
}
Object.assign(TopLevelCallbackBookKeeping.prototype, {
destructor: function() {
this.topLevelType = null;
this.nativeEvent = null;
this.targetInst = null;
this.ancestors.length = 0;
},
});
PooledClass.addPoolingTo(
TopLevelCallbackBookKeeping,
PooledClass.threeArgumentPooler,
);

function handleTopLevelImpl(bookKeeping) {
var targetInst = bookKeeping.targetInst;
Expand Down Expand Up @@ -180,7 +189,7 @@ var ReactDOMEventListener = {
targetInst = null;
}

var bookKeeping = TopLevelCallbackBookKeeping.getPooled(
var bookKeeping = getTopLevelCallbackBookKeeping(
topLevelType,
nativeEvent,
targetInst,
Expand All @@ -191,7 +200,7 @@ var ReactDOMEventListener = {
// `preventDefault`.
ReactGenericBatching.batchedUpdates(handleTopLevelImpl, bookKeeping);
} finally {
TopLevelCallbackBookKeeping.release(bookKeeping);
releaseTopLevelCallbackBookKeeping(bookKeeping);
}
},
};
Expand Down

0 comments on commit d9f717d

Please sign in to comment.