Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[performance] Replace hasOwnProperty in child processing with typeof undefined check #3665

Merged
merged 2 commits into from
Apr 22, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/utils/ReactChildren.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function mapSingleChildIntoContext(traverseContext, child, name, i) {
var mapBookKeeping = traverseContext;
var mapResult = mapBookKeeping.mapResult;

var keyUnique = !mapResult.hasOwnProperty(name);
var keyUnique = ('undefined' === typeof mapResult[name]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally we'd just write (mapResult[name] === undefined) – I assume that's no slower?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typeof is about 20-25% faster than direct equality according to http://jsperf.com/hasownproperty-vs-in-vs-undefined/81

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a transpiler that can turn === undefined into === void 0 which is faster yet but ugly.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use the constant (string literal) on the right hand side. Which is triggering a lint warning which is failing the unit tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll update to match the styling rules.

if (__DEV__) {
warning(
keyUnique,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/flattenChildren.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var warning = require('warning');
function flattenSingleChildIntoContext(traverseContext, child, name) {
// We found a component instance.
var result = traverseContext;
var keyUnique = !result.hasOwnProperty(name);
var keyUnique = ('undefined' === typeof result[name]);
if (__DEV__) {
warning(
keyUnique,
Expand Down