Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Use precise=false for performance when parsing unchanging code #5395

Merged
merged 3 commits into from
Oct 3, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/extensions/default/JavaScriptCodeHints/Session.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ define(function (require, exports, module) {
var cm = this.editor._codeMirror;

if (cursor) {
return cm.getTokenAt(cursor, true);
return cm.getTokenAt(cursor);
} else {
return cm.getTokenAt(this.getCursor(), true);
return cm.getTokenAt(this.getCursor());
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/language/HTMLUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ define(function (require, exports, module) {
outerMode = editor._codeMirror.getMode(),
tokenModeName;

while (TokenUtils.moveNextToken(ctx)) {
while (TokenUtils.moveNextToken(ctx, false)) {
tokenModeName = CodeMirror.innerMode(outerMode, ctx.token.state).mode.name;
if (inBlock) {
if (!currentBlock.end) {
Expand Down
20 changes: 16 additions & 4 deletions src/utils/TokenUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,15 @@ define(function (require, exports, module) {
/**
* Moves the given context backwards by one token.
* @param {editor:{CodeMirror}, pos:{ch:{string}, line:{number}}, token:{object}} ctx
* @param {boolean=} precise If code is being edited, use true (default) for accuracy.
* If parsing unchanging code, use false to use cache for performance.
* @return {boolean} whether the context changed
*/
function movePrevToken(ctx) {
function movePrevToken(ctx, precise) {
if (precise === undefined) {
precise = true;
}

if (ctx.pos.ch <= 0 || ctx.token.start <= 0) {
//move up a line
if (ctx.pos.line <= 0) {
Expand All @@ -64,17 +70,23 @@ define(function (require, exports, module) {
} else {
ctx.pos.ch = ctx.token.start;
}
ctx.token = ctx.editor.getTokenAt(ctx.pos, true);
ctx.token = ctx.editor.getTokenAt(ctx.pos, precise);
return true;
}

/**
* Moves the given context forward by one token.
* @param {editor:{CodeMirror}, pos:{ch:{string}, line:{number}}, token:{object}} ctx
* @param {boolean=} precise If code is being edited, use true (default) for accuracy.
* If parsing unchanging code, use false to use cache for performance.
* @return {boolean} whether the context changed
*/
function moveNextToken(ctx) {
function moveNextToken(ctx, precise) {
var eol = ctx.editor.getLine(ctx.pos.line).length;
if (precise === undefined) {
precise = true;
}

if (ctx.pos.ch >= eol || ctx.token.end >= eol) {
//move down a line
if (ctx.pos.line >= ctx.editor.lineCount() - 1) {
Expand All @@ -85,7 +97,7 @@ define(function (require, exports, module) {
} else {
ctx.pos.ch = ctx.token.end + 1;
}
ctx.token = ctx.editor.getTokenAt(ctx.pos, true);
ctx.token = ctx.editor.getTokenAt(ctx.pos, precise);
return true;
}

Expand Down