Skip to content

Commit

Permalink
stop reinstantiating a renderer every call.
Browse files Browse the repository at this point in the history
  • Loading branch information
chjj committed Dec 4, 2013
1 parent d116575 commit 2636f85
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions lib/marked.js
Original file line number Diff line number Diff line change
Expand Up @@ -510,14 +510,11 @@ inline.breaks = merge({}, inline.gfm, {
* Inline Lexer & Compiler
*/

function InlineLexer(links, options, renderer) {
function InlineLexer(links, options) {
this.options = options || marked.defaults;
this.links = links;
this.rules = inline.normal;
if (!renderer) {
renderer = new Renderer();
}
this.renderer = renderer;
this.renderer = this.options.renderer || new Renderer;

if (!this.links) {
throw new
Expand Down Expand Up @@ -740,8 +737,7 @@ InlineLexer.prototype.mangle = function(text) {
* Renderer
*/

function Renderer(options) {
}
function Renderer() {}

Renderer.prototype.blockcode = function(code, lang) {
if (!lang) {
Expand Down Expand Up @@ -848,15 +844,12 @@ Renderer.prototype.image = function(href, title, text) {
* Parsing & Compiling
*/

function Parser(options, renderer) {
function Parser(options) {
this.tokens = [];
this.token = null;
if (options instanceof Renderer) {
options = null;
renderer = options;
}
this.renderer = renderer || new Renderer();
this.options = options || marked.defaults;
this.options.renderer = this.options.renderer || new Renderer;
this.renderer = this.options.renderer;
}

/**
Expand Down Expand Up @@ -1103,7 +1096,7 @@ function marked(src, opt, callback) {
var out, err;

try {
out = Parser.parse(tokens, opt, opt.renderer);
out = Parser.parse(tokens, opt);
} catch (e) {
err = e;
}
Expand Down Expand Up @@ -1143,7 +1136,7 @@ function marked(src, opt, callback) {
}
try {
if (opt) opt = merge({}, marked.defaults, opt);
return Parser.parse(Lexer.lex(src, opt), opt, opt && opt.renderer);
return Parser.parse(Lexer.lex(src, opt), opt);
} catch (e) {
e.message += '\nPlease report this to https://github.com/chjj/marked.';
if ((opt || marked.defaults).silent) {
Expand Down Expand Up @@ -1175,7 +1168,8 @@ marked.defaults = {
silent: false,
highlight: null,
langPrefix: 'lang-',
smartypants: false
smartypants: false,
renderer: new Renderer
};

/**
Expand Down

0 comments on commit 2636f85

Please sign in to comment.