Skip to content

Commit 4308889

Browse files
committed
Don't use object pool for initialOldData, and properly recycle tempObject
1 parent 18b25a0 commit 4308889

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/core/a-entity.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ class AEntity extends ANode {
278278
/**
279279
* Initialize component.
280280
*
281-
* @param {string} attrName - Attribute name asociated to the component.
281+
* @param {string} attrName - Attribute name associated to the component.
282282
* @param {object} data - Component data
283283
* @param {boolean} isDependency - True if the component is a dependency.
284284
*/

src/core/component.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ var upperCaseRegExp = new RegExp('[A-Z]+');
1919

2020
// Object pools by component, created upon registration.
2121
var objectPools = {};
22+
var emptyInitialOldData = Object.freeze({});
2223

2324
/**
2425
* Component class definition.
@@ -203,6 +204,7 @@ Component.prototype = {
203204
// If value is an object, copy it to our pooled newAttrValue object to use to update
204205
// the attrValue.
205206
tempObject = this.objectPool.use();
207+
utils.objectPool.clearObject(tempObject);
206208
newAttrValue = utils.extend(tempObject, value);
207209
} else {
208210
newAttrValue = this.parseAttrValueForCache(value);
@@ -223,7 +225,7 @@ Component.prototype = {
223225
}
224226
utils.objectPool.clearObject(this.attrValue);
225227
this.attrValue = extendProperties(this.attrValue, newAttrValue, this.isObjectBased);
226-
utils.objectPool.clearObject(tempObject);
228+
this.objectPool.recycle(tempObject);
227229
},
228230

229231
/**
@@ -271,7 +273,7 @@ Component.prototype = {
271273
*
272274
* @param {string} attrValue - HTML attribute value.
273275
* If undefined, use the cached attribute value and continue updating properties.
274-
* @param {boolean} clobber - The previous component data is overwritten by the atrrValue.
276+
* @param {boolean} clobber - The previous component data is overwritten by the attrValue.
275277
*/
276278
updateProperties: function (attrValue, clobber) {
277279
var el = this.el;
@@ -324,9 +326,8 @@ Component.prototype = {
324326

325327
// For oldData, pass empty object to multiple-prop schemas or object single-prop schema.
326328
// Pass undefined to rest of types.
327-
initialOldData = this.isObjectBased ? this.objectPool.use() : undefined;
329+
initialOldData = this.isObjectBased ? emptyInitialOldData : undefined;
328330
this.update(initialOldData);
329-
if (this.isObjectBased) { this.objectPool.recycle(initialOldData); }
330331

331332
// Play the component if the entity is playing.
332333
if (el.isPlaying) { this.play(); }

0 commit comments

Comments
 (0)