Просмотр исходного кода

Speed up interpreted mode by saving the compiled regex in escape_regex.

tags/0.5.0-vsc
Sahab Yazdani 15 лет назад
Родитель
Сommit
cfc6c8f80e
1 измененных файлов: 10 добавлений и 6 удалений
  1. +10
    -6
      mustache.js

+ 10
- 6
mustache.js Просмотреть файл

@@ -11,6 +11,8 @@ var Mustache = function() {
ParserException.prototype = {}; ParserException.prototype = {};
var Renderer = function(send_func, mode) { var Renderer = function(send_func, mode) {
this._escapeCompiledRegex = null;
this.user_send_func = send_func; this.user_send_func = send_func;
if (mode==='interpreter' || !mode) { if (mode==='interpreter' || !mode) {
this.commandSet = this.interpreter; this.commandSet = this.interpreter;
@@ -239,13 +241,15 @@ var Mustache = function() {
escape_regex: function(text) { escape_regex: function(text) {
// thank you Simon Willison // thank you Simon Willison
var specials = [
'/', '.', '*', '+', '?', '|',
'(', ')', '[', ']', '{', '}', '\\'
];
var compiled_regex = new RegExp('(\\' + specials.join('|\\') + ')', 'g');
if (!this._escapeCompiledRegex) {
var specials = [
'/', '.', '*', '+', '?', '|',
'(', ')', '[', ']', '{', '}', '\\'
];
this._escapeCompiledRegex = new RegExp('(\\' + specials.join('|\\') + ')', 'g');
}
return text.replace(compiled_regex, '\\$1');
return text.replace(this._escapeCompiledRegex, '\\$1');
}, },
isWhitespace: function(token) { isWhitespace: function(token) {


Загрузка…
Отмена
Сохранить