Permalink
Browse files

Performance optimization

  • Loading branch information...
1 parent 9d9a10c commit 40e08fb37f610072467d07c6f97086e99663dfbc @baryshev committed Nov 14, 2012
Showing with 17 additions and 9 deletions.
  1. +2 −2 ect.min.js
  2. +14 −6 lib/ect.js
  3. +1 −1 package.json
View
Oops, something went wrong.
View
@@ -1,5 +1,5 @@
/*!
- * ECT CoffeeScript template engine v0.3.4
+ * ECT CoffeeScript template engine v0.3.5
* https://github.com/baryshev/ect
*
* Copyright 2012, Vadim M. Baryshev <vadimbaryshev@gmail.com>
@@ -43,10 +43,11 @@
cache = {},
watchers = {},
indentChars = { ':' : ':', '>' : '>' },
- escapeExp = /[&<>"]/g,
- escapedChars = { '&' : '&#38;', '<' : '&#60;', '>' : '&#62;', '"' : '&#34;' },
- escapeHandler = function (char) { return escapedChars[char]; },
-
+ escapeExp = /[&<>"]/,
+ escapeAmpExp = /&/g,
+ escapeLtExp = /</g,
+ escapeGtExp = />/g,
+ escapeQuotExp = /"/g,
regExpEscape = function (str) {
return String(str).replace(/([.*+?\^=!:${}()|\[\]\/\\])/g, '\\$1');
},
@@ -254,7 +255,14 @@
};
TemplateContext.prototype.escape = function (text) {
- return (text == null) ? '' : text.toString().replace(escapeExp, escapeHandler);
+ if (text == null) {
+ return '';
+ }
+ var result = text.toString();
+ if (!escapeExp.test(result)) {
+ return result;
+ }
+ return result.replace(escapeAmpExp, '&#38;').replace(escapeLtExp, '&#60;').replace(escapeGtExp, '&#62;').replace(escapeQuotExp, '&#34;');
};
TemplateContext.prototype.block = function (name) {
View
@@ -1,6 +1,6 @@
{
"name" : "ect",
- "version" : "0.3.4",
+ "version" : "0.3.5",
"description" : "CoffeeScript template engine",
"keywords": [ "template", "coffeescript" ],
"author" : "Vadim M. Baryshev <vadimbaryshev@gmail.com>",

0 comments on commit 40e08fb

Please sign in to comment.