From d9c69a0975f5790376d12c79f016eb3ade6a2f1a Mon Sep 17 00:00:00 2001 From: rolux Date: Sat, 26 May 2012 13:11:06 +0200 Subject: [PATCH] improve performance of DocPanel by returning tokens (not source) from Ox.doc and making Ox.SyntaxHighlighter accept tokens --- source/Ox.UI/js/Code/Ox.SyntaxHighlighter.js | 9 ++++----- source/Ox/js/JavaScript.js | 10 ++++++---- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/source/Ox.UI/js/Code/Ox.SyntaxHighlighter.js b/source/Ox.UI/js/Code/Ox.SyntaxHighlighter.js index b29e5f4b..cbff321d 100644 --- a/source/Ox.UI/js/Code/Ox.SyntaxHighlighter.js +++ b/source/Ox.UI/js/Code/Ox.SyntaxHighlighter.js @@ -13,7 +13,7 @@ Ox.SyntaxHighlighter Syntax Highlighter showLineNumbers If true, show line numbers showWhitespace If true, show whitespace showTabs If true, show tabs - source JavaScript source + source JavaScript source, or array of tokens stripComments If true, strip comments tabSize Number of spaces per tab self Shared private variable @@ -52,10 +52,9 @@ Ox.SyntaxHighlighter = function(options, self) { '\u2192' : '' ) + Ox.repeat(' ', self.options.tabSize - self.options.showTabs), whitespace = self.options.showWhitespace ? '\u00B7' : ' '; - self.options.source = self.options.source - .replace(/\r\n/g, '\n') - .replace(/\r/g, '\n'); - tokens = Ox.tokenize(self.options.source); + tokens = Ox.isArray(self.options.source) + ? self.options.source + : Ox.tokenize(self.options.source); tokens.forEach(function(token, i) { var classNames, type = token.type == 'identifier' diff --git a/source/Ox/js/JavaScript.js b/source/Ox/js/JavaScript.js index e781f8c7..3bba0132 100644 --- a/source/Ox/js/JavaScript.js +++ b/source/Ox/js/JavaScript.js @@ -18,7 +18,11 @@ Ox.doc Generates documentation for annotated JavaScript "event", "function" or "object". section Section in the file - source Source code + source <[o]> Source code (array of tokens) + column Column + line Line + type Type (see Ox.tokenize for a list of types) + value Value summary One-line summary usage <[o]> Usage (array of doc objects) Present if the type of the item is @@ -156,9 +160,7 @@ Ox.doc = (function() { if (/^[A-Z]/.test(item.name)) { // main item // include leading whitespace - item.source = parseTokens(tokens[i]).map(function(token) { - return token.value; - }).join(''); + item.source = parseTokens(tokens[i]); item.line = source.slice(0, item.source[0].offset) .split('\n').length; items.push(item);