Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
Minor tweaks to reuse objects and skip forEach during boot
Browse files Browse the repository at this point in the history
Reuse the descriptor objects where possible. For non generational
GC this reduces the GC churn.

Use c-style for loops instead of forEach since forEach is slow
  • Loading branch information
arv committed Apr 8, 2014
1 parent e9238fd commit 399d28a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 17 deletions.
48 changes: 32 additions & 16 deletions src/wrappers.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,29 @@ window.ShadowDOMPolyfill = {};
var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;

function mixin(to, from) {
getOwnPropertyNames(from).forEach(function(name) {
var names = getOwnPropertyNames(from);
for (var i = 0; i < names.length; i++) {
var name = names[i];
defineProperty(to, name, getOwnPropertyDescriptor(from, name));
});
}
return to;
};

function mixinStatics(to, from) {
getOwnPropertyNames(from).forEach(function(name) {
var names = getOwnPropertyNames(from);
for (var i = 0; i < names.length; i++) {
var name = names[i];
switch (name) {
case 'arguments':
case 'caller':
case 'length':
case 'name':
case 'prototype':
case 'toString':
return;
continue;
}
defineProperty(to, name, getOwnPropertyDescriptor(from, name));
});
}
return to;
};

Expand All @@ -69,6 +73,18 @@ window.ShadowDOMPolyfill = {};
}
}

var nonEnumerableDataDescriptor = {
value: undefined,
configurable: true,
enumerable: false,
writable: true
};

function defineNonEnumerableDataProperty(object, name, value) {
nonEnumerableDataDescriptor.value = value;
defineProperty(object, name, nonEnumerableDataDescriptor);
}

// Mozilla's old DOM bindings are bretty busted:
// https://bugzilla.mozilla.org/show_bug.cgi?id=855844
// Make sure they are create before we start modifying things.
Expand Down Expand Up @@ -213,12 +229,9 @@ window.ShadowDOMPolyfill = {};
addForwardingProperties(nativePrototype, wrapperPrototype);
if (opt_instance)
registerInstanceProperties(wrapperPrototype, opt_instance);
defineProperty(wrapperPrototype, 'constructor', {
value: wrapperConstructor,
configurable: true,
enumerable: false,
writable: true
});

defineNonEnumerableDataProperty(
wrapperPrototype, 'constructor', wrapperConstructor);
// Set it again. Some VMs optimizes objects that are used as prototypes.
wrapperConstructor.prototype = wrapperPrototype;
}
Expand Down Expand Up @@ -348,12 +361,15 @@ window.ShadowDOMPolyfill = {};
node.polymerWrapper_ = wrapper;
}

var getterDescriptor = {
get: undefined,
configurable: true,
enumerable: true
};

function defineGetter(constructor, name, getter) {
defineProperty(constructor.prototype, name, {
get: getter,
configurable: true,
enumerable: true
});
getterDescriptor.get = getter;
defineProperty(constructor.prototype, name, getterDescriptor);
}

function defineWrapGetter(constructor, name) {
Expand Down
4 changes: 3 additions & 1 deletion src/wrappers/NodeList.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@

var wrap = scope.wrap;

var nonEnumDescriptor = {enumerable: false};

function nonEnum(obj, prop) {
Object.defineProperty(obj, prop, {enumerable: false});
Object.defineProperty(obj, prop, nonEnumDescriptor);
}

function NodeList() {
Expand Down

0 comments on commit 399d28a

Please sign in to comment.