Skip to content

Commit d9048b4

Browse files
committed
Use hasOwnProperty to check for object properties
I've been doing some performance profiling of Aphrodite and noticed that even after updating to inline-style-prefixer 3.0.0, the prefixValue function was still more expensive than I expected. After looking at the CPU profile and the lines highlighted here, it seems that checking for the existence of these object properties using `foo[bar]` is much more expensive than checking using `foo.hasOwnProperty(bar)`.
1 parent 11ba89c commit d9048b4

File tree

14 files changed

+18
-18
lines changed

14 files changed

+18
-18
lines changed

modules/dynamic/createPrefixer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export default function createPrefixer(
111111
}
112112

113113
// add prefixes to properties
114-
if (this._requiresPrefix[property]) {
114+
if (this._requiresPrefix.hasOwnProperty(property)) {
115115
style[this._browserInfo.jsPrefix + capitalizeString(property)] = value
116116
if (!this._keepUnprefixed) {
117117
delete style[property]

modules/dynamic/plugins/flexboxIE.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export default function flexboxIE(
3636
PluginMetaData
3737
): ?Array<any> | ?any {
3838
if (
39-
(alternativeProps[property] ||
39+
(alternativeProps.hasOwnProperty(property) ||
4040
property === 'display' && typeof value === 'string' && value.indexOf('flex') > -1) &&
4141
((browserName === 'ie_mob' || browserName === 'ie') && browserVersion === 10)
4242
) {
@@ -45,10 +45,10 @@ PluginMetaData
4545
if (!keepUnprefixed && !Array.isArray(style[property])) {
4646
delete style[property]
4747
}
48-
if (property === 'display' && alternativeValues[value]) {
48+
if (property === 'display' && alternativeValues.hasOwnProperty(value)) {
4949
return getPrefixedValue(cssPrefix + alternativeValues[value], value, keepUnprefixed)
5050
}
51-
if (alternativeProps[property]) {
51+
if (alternativeProps.hasOwnProperty(property)) {
5252
style[alternativeProps[property]] = alternativeValues[value] || value
5353
}
5454
}

modules/dynamic/plugins/flexboxOld.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ PluginMetaData
7070
style.WebkitBoxDirection = 'normal'
7171
}
7272
}
73-
if (property === 'display' && alternativeValues[value]) {
73+
if (property === 'display' && alternativeValues.hasOwnProperty(value)) {
7474
return getPrefixedValue(cssPrefix + alternativeValues[value], value, keepUnprefixed)
7575
}
76-
if (alternativeProps[property]) {
76+
if (alternativeProps.hasOwnProperty(property)) {
7777
style[alternativeProps[property]] = alternativeValues[value] || value
7878
}
7979
}

modules/dynamic/plugins/sizing.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export default function sizing(
2929
): ?Array<any> | ?any {
3030
// This might change in the future
3131
// Keep an eye on it
32-
if (properties[property] && values[value]) {
32+
if (properties.hasOwnProperty(property) && values.hasOwnProperty(value)) {
3333
return getPrefixedValue(cssPrefix + value, value, keepUnprefixed)
3434
}
3535
}

modules/dynamic/plugins/transition.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export default function transition(
1919
style: Object,
2020
{ cssPrefix, keepUnprefixed, requiresPrefix }: PluginMetaData
2121
): ?Array<any> | ?any {
22-
if (typeof value === 'string' && properties[property]) {
22+
if (typeof value === 'string' && properties.hasOwnProperty(property)) {
2323
// memoize the prefix array for later use
2424
if (!requiresPrefixDashCased) {
2525
requiresPrefixDashCased = Object.keys(requiresPrefix).map(prop => hyphenateProperty(prop))

modules/generator/generateDynamicPrefixMap.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export default function generateDynamicPrefixMap(browserList: Object): Object {
3737

3838
for (let i = 0, len = browsers.length; i < len; ++i) {
3939
const browser = browsers[i]
40-
if (!prefixMap[browser]) {
40+
if (!prefixMap.hasOwnProperty(browser)) {
4141
prefixMap[browser] = {}
4242
}
4343

modules/generator/generatePluginList.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default function getRecommendedPlugins(browserList: Object): Array<string
88
const browserSupportByPlugin = pluginMap[plugin]
99

1010
for (const browser in browserSupportByPlugin) {
11-
if (browserList[browser]) {
11+
if (browserList.hasOwnProperty(browser)) {
1212
const browserVersion = browserSupportByPlugin[browser]
1313

1414
if (browserList[browser] < browserVersion) {

modules/static/plugins/cursor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const values = {
99
}
1010

1111
export default function cursor(property: string, value: any): ?Array<string> {
12-
if (property === 'cursor' && values[value]) {
12+
if (property === 'cursor' && values.hasOwnProperty(value)) {
1313
return prefixes.map(prefix => prefix + value)
1414
}
1515
}

modules/static/plugins/flex.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const values = {
55
}
66

77
export default function flex(property: string, value: any): ?Array<string> {
8-
if (property === 'display' && values[value]) {
8+
if (property === 'display' && values.hasOwnProperty(value)) {
99
return ['-webkit-box', '-moz-box', `-ms-${value}box`, `-webkit-${value}`, value]
1010
}
1111
}

modules/static/plugins/flexboxIE.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const alternativeProps = {
1717
}
1818

1919
export default function flexboxIE(property: string, value: any, style: Object): void {
20-
if (alternativeProps[property]) {
20+
if (alternativeProps.hasOwnProperty(property)) {
2121
style[alternativeProps[property]] = alternativeValues[value] || value
2222
}
2323
}

0 commit comments

Comments
 (0)