Ticket #2648 (closed defect: wontfix)
toCamelCase is slow on IE6
| Reported by: | guest | Owned by: | anonymous |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | General | Version: | 0.4.2 |
| Severity: | normal | Keywords: | |
| Cc: |
Description
(from sdrye at atg.com, ATG CLA on file)
The toCamelCase function is slow on IE6, and can be improved for the other browsers, too.
Using Tito Web Studio to profile laying out our UI onresize, I noticed that toCamelCase was using 20+% of the time on IE6 (~7% on Firefox 2). Adding a simple cache to the function drastically sped it up, so it was only taking 7% of the time on IE6 (~2% on Firefox).
I think adding this cache is a good idea, since the set of selectors is not that large. It could even be pre-populated, but that would increase the download size so it might not be worth it.
Here's my patch (not in diff form, since it's pretty trivial):
dojo.html.toCamelCaseMap = {};
dojo.html.toCamelCase = function(/* string */selector){
// summary
// Translates a CSS selector string to a camel-cased one.
if (dojo.html.toCamelCaseMap[selector]) return dojo.html.toCamelCaseMap[selector];
var arr = selector.split('-'), cc = arr[0];
for(var i = 1; i < arr.length; i++) {
cc += arr[i].charAt(0).toUpperCase() + arr[i].substring(1);
}
dojo.html.toCamelCaseMap[selector] = cc;
return cc; // string
}