prototype: Improve performance of String.prototype.escapeHTML by using a cached div and text node. Closes #6937.

This commit is contained in:
Sam Stephenson 2007-01-27 18:33:03 +00:00
parent 8ea007df28
commit c556c89627
2 changed files with 12 additions and 4 deletions

View File

@ -1,5 +1,7 @@
*SVN*
* Improve performance of String.prototype.escapeHTML by using a cached div and text node. Closes #6937. [altblue]
* Make setStyle() with opacity: 0 in Internet Explorer work correctly. [Thomas Fuchs]
* Form.Element.activate shouldn't raise an exception when the form or field is hidden. [sam]

View File

@ -66,10 +66,9 @@ Object.extend(String.prototype, {
},
escapeHTML: function() {
var div = document.createElement('div');
var text = document.createTextNode(this);
div.appendChild(text);
return div.innerHTML;
var self = arguments.callee;
self.text.data = this;
return self.div.innerHTML;
},
unescapeHTML: function() {
@ -152,6 +151,13 @@ String.prototype.gsub.prepareReplacement = function(replacement) {
String.prototype.parseQuery = String.prototype.toQueryParams;
Object.extend(String.prototype.escapeHTML, {
div: document.createElement('div'),
text: document.createTextNode('')
});
with (String.prototype.escapeHTML) div.appendChild(text);
var Template = Class.create();
Template.Pattern = /(^|.|\r|\n)(#\{(.*?)\})/;
Template.prototype = {