mirror of
https://github.com/Polymer/polymer.git
synced 2025-02-25 18:55:30 -06:00
Merge pull request #3279 from nazar-pc/case-convertion-performance-improvement
Improved performance of Polymer.CaseMap.* functions
This commit is contained in:
commit
2586ede5ac
@ -12,32 +12,24 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
||||
Polymer.CaseMap = {
|
||||
|
||||
_caseMap: {},
|
||||
_rx: {
|
||||
dashToCamel: /-[a-z]/g,
|
||||
camelToDash: /([A-Z])/g
|
||||
},
|
||||
|
||||
dashToCamelCase: function(dash) {
|
||||
var mapped = Polymer.CaseMap._caseMap[dash];
|
||||
if (mapped) {
|
||||
return mapped;
|
||||
}
|
||||
// TODO(sjmiles): is rejection test actually helping perf?
|
||||
if (dash.indexOf('-') < 0) {
|
||||
return Polymer.CaseMap._caseMap[dash] = dash;
|
||||
}
|
||||
return Polymer.CaseMap._caseMap[dash] = dash.replace(/-([a-z])/g,
|
||||
function(m) {
|
||||
return m[1].toUpperCase();
|
||||
}
|
||||
return this._caseMap[dash] || (
|
||||
this._caseMap[dash] = dash.indexOf('-') < 0 ? dash : dash.replace(this._rx.dashToCamel,
|
||||
function(m) {
|
||||
return m[1].toUpperCase();
|
||||
}
|
||||
)
|
||||
);
|
||||
},
|
||||
|
||||
camelToDashCase: function(camel) {
|
||||
var mapped = Polymer.CaseMap._caseMap[camel];
|
||||
if (mapped) {
|
||||
return mapped;
|
||||
}
|
||||
return Polymer.CaseMap._caseMap[camel] = camel.replace(/([a-z][A-Z])/g,
|
||||
function (g) {
|
||||
return g[0] + '-' + g[1].toLowerCase()
|
||||
}
|
||||
return this._caseMap[camel] || (
|
||||
this._caseMap[camel] = camel.replace(this._rx.camelToDash, '-$1').toLowerCase()
|
||||
);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user