Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 240990 Details for
Bug 430632
investigate passing text model around instead of strings within TextStyler
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
patch
patch.txt (text/plain), 16.86 KB, created by
Grant Gayed
on 2014-03-18 15:20:51 EDT
(
hide
)
Description:
patch
Filename:
MIME Type:
Creator:
Grant Gayed
Created:
2014-03-18 15:20:51 EDT
Size:
16.86 KB
patch
obsolete
>diff --git a/bundles/org.eclipse.orion.client.editor/web/orion/editor/textStyler.js b/bundles/org.eclipse.orion.client.editor/web/orion/editor/textStyler.js >index 38ca2a7..0293315 100644 >--- a/bundles/org.eclipse.orion.client.editor/web/orion/editor/textStyler.js >+++ b/bundles/org.eclipse.orion.client.editor/web/orion/editor/textStyler.js >@@ -24,7 +24,7 @@ > > // Styles > var caretLineStyle = {styleClass: "meta annotation currentLine"}; //$NON-NLS-0$ >- >+var NEW = 1; > var PUNCTUATION_SECTION_BEGIN = ".begin"; //$NON-NLS-0$ > var PUNCTUATION_SECTION_END = ".end"; //$NON-NLS-0$ > >@@ -39,7 +39,65 @@ > var spacePattern = {regex: /[ ]/g, style: {styleClass: "punctuation separator space", unmergeable: true}}; //$NON-NLS-0$ > var tabPattern = {regex: /\t/g, style: {styleClass: "punctuation separator tab", unmergeable: true}}; //$NON-NLS-0$ > >- var _findMatch = function(regex, text, startIndex, testBeforeMatch) { >+ var _findMatch_latest = function(regex, model, startIndex, endIndex, testBeforeMatch) { >+ /* >+ * testBeforeMatch provides a potential optimization for callers that do not strongly expect to find >+ * a match. If this argument is defined then test() is initially called on the regex, which executes >+ * significantly faster than exec(). If a match is found then the regex's lastIndex is reverted to >+ * its pre-test() value, and exec() is then invoked on it in order to get the match details. >+ */ >+ >+ var initialLastIndex = regex.lastIndex; >+ >+ var lineIndex = model.getLineAtOffset(startIndex); >+ var endLineIndex = model.getLineAtOffset(endIndex); >+ >+ var lineStart = model.getLineStart(lineIndex); >+ >+ var lineString = model.getLine(lineIndex); >+ regex.lastIndex = startIndex - lineStart; // TODO is the -1 still appropriate? >+ while (lineIndex <= endLineIndex) { >+ var result; >+ if (testBeforeMatch) { >+ var revertIndex = regex.lastIndex; >+ if (regex.test(lineString)) { >+ regex.lastIndex = revertIndex; >+ result = regex.exec(lineString); >+ } >+ } else { >+ result = regex.exec(lineString); >+ } >+ if (result) { >+ result.index += model.getLineStart(lineIndex); >+ regex.lastIndex = initialLastIndex; >+ return result; >+ } >+ if (endLineIndex < ++lineIndex) break; >+// lineString = model.getLine(lineIndex, true); >+ lineStart = model.getLineStart(lineIndex); >+// if (lineStart + lineString.length > endIndex) { >+// lineString = lineString.substring(0, endIndex - lineStart) >+// } >+ /* >+ * TODO the following passes includeLineDelimiter then subtracts 1 to make it run faster, >+ * which is potentially wrong. >+ */ >+ var lineEnd = model.getLineEnd(lineIndex, true) - 1; >+ if (endIndex < lineEnd) { >+ lineString = model.getText(/*model.getLineStart(lineIndex)*/lineStart, endIndex); >+ } else { >+ lineString = model.getText(/*model.getLineStart(lineIndex)*/lineStart, lineEnd); >+ // lineString = model.getLine(lineIndex); // slower >+ } >+ regex.lastIndex = 0; >+ } >+ regex.lastIndex = initialLastIndex; >+ return null; >+ }; >+ >+ var _findMatch_orig = function(regex, model, startIndex, endIndex, testBeforeMatch) { >+ var text = model.getText(/*startIndex*/0, endIndex); >+ > /* > * testBeforeMatch provides a potential optimization for callers that do not strongly expect to find > * a match. If this argument is defined then test() is initially called on the regex, which executes >@@ -99,6 +157,34 @@ > regex.lastIndex = initialLastIndex; > return null; > }; >+ >+ var _findMatch_new = function(regex, model, startIndex, endIndex, testBeforeMatch) { >+ var text = model.getText(/*startIndex*/0, endIndex); >+ >+ /* >+ * testBeforeMatch provides a potential optimization for callers that do not strongly expect to find >+ * a match. If this argument is defined then test() is initially called on the regex, which executes >+ * significantly faster than exec(). If a match is found then the regex's lastIndex is reverted to >+ * its pre-test() value, and exec() is then invoked on it in order to get the match details. >+ */ >+ >+ var result; >+ var initialLastIndex = regex.lastIndex; >+ regex.lastIndex = startIndex; >+ if (testBeforeMatch) { >+ var revertIndex = regex.lastIndex; >+ if (regex.test(text)) { >+ regex.lastIndex = revertIndex; >+ result = regex.exec(text); >+ } >+ } else { >+ result = regex.exec(text); >+ } >+ regex.lastIndex = initialLastIndex; >+ return result; >+ }; >+ var _findMatch = NEW ? _findMatch_latest : _findMatch_orig; >+ > var substituteCaptureValues = function(regex, resolvedResult) { > var regexString = regex.toString(); > captureReferenceRegex.lastIndex = 0; >@@ -117,9 +203,9 @@ > /* return an updated regex, remove the leading '/' and trailing /FLAGS */ > return new RegExp(regexString.substring(1, regexString.length - 1 - FLAGS.length), FLAGS); > }; >- var updateMatch = function(match, text, matches, minimumIndex) { >+ var updateMatch = function(match, matches, model, startIndex, endIndex) { > var regEx = match.pattern.regex ? match.pattern.regex : match.pattern.regexBegin; >- var result = _findMatch(regEx, text, minimumIndex, true); >+ var result = _findMatch(regEx, model, startIndex, endIndex, true); > if (result) { > match.result = result; > for (var i = 0; i < matches.length; i++) { >@@ -163,8 +249,8 @@ > resultStyles.push({start: i, end: fullStyle.end, style: fullStyle.style}); > } > }; >- var parse = function(text, offset, block, styles, ignoreCaptures) { >- if (!text) { >+ var parse = function(model, /*offset*/startIndex, endIndex, block, styles, ignoreCaptures) { >+ if (startIndex === endIndex) { > return; > } > var patterns = block.getLinePatterns(); >@@ -176,7 +262,7 @@ > patterns.forEach(function(current) { > var regex = current.regex || current.regexBegin; > regex.oldLastIndex = regex.lastIndex; >- var result = _findMatch(regex, text, 0); >+ var result = _findMatch(regex, model, startIndex, endIndex); > if (result) { > matches.push({result: result, pattern: current}); > } >@@ -198,7 +284,7 @@ > > if (current.result.index < index) { > /* processing of another match has moved index beyond this match */ >- updateMatch(current, text, matches, index); >+ updateMatch(current, matches, model, index, endIndex); > continue; > } > >@@ -209,10 +295,10 @@ > if (current.pattern.regex) { /* line pattern defined by a "match" */ > result = current.result; > end = start + result[0].length; >- var tokenStyle = {start: offset + start, end: offset + end, style: current.pattern.pattern.name}; >+ var tokenStyle = {start: /*offset +*/ start, end: /*offset +*/ end, style: current.pattern.pattern.name}; > if (!ignoreCaptures) { > if (current.pattern.pattern.captures) { >- getCaptureStyles(result, current.pattern.pattern.captures, offset + start, substyles); >+ getCaptureStyles(result, current.pattern.pattern.captures, /*offset +*/ start, substyles); > } > substyles.sort(function(a,b) { > if (a.start < b.start) { >@@ -240,31 +326,31 @@ > var endRegex = current.pattern.regexEnd; > endRegex = substituteCaptureValues(endRegex, current.result); > >- result = _findMatch(endRegex, text, current.result.index + current.result[0].length); >+ result = _findMatch(endRegex, model, current.result.index + current.result[0].length, endIndex); > if (!result) { > eolRegex.lastIndex = 0; >- result = eolRegex.exec(text); >+ result = _findMatch(eolRegex, model, /*startIndex*/endIndex, endIndex); // TODO verify that this works > } > end = result.index + result[0].length; >- styles.push({start: offset + start, end: offset + end, style: current.pattern.pattern.name}); >+ styles.push({start: /*offset +*/ start, end: /*offset +*/ end, style: current.pattern.pattern.name}); > } > index = result.index + result[0].length; >- updateMatch(current, text, matches, index); >+ updateMatch(current, matches, model, index, endIndex); > } > patterns.forEach(function(current) { > var regex = current.regex || current.regexBegin; > regex.lastIndex = regex.oldLastIndex; > }); > }; >- var computeBlocks = function(model, text, block, offset) { >- if (!text) { >+ var computeBlocks = function(model, startIndex, endIndex, block/*, offset*/) { >+ if (startIndex === endIndex) { > return []; > } > > var results = []; > var matches = []; > block.getBlockPatterns().forEach(function(current) { >- var result = _findMatch(current.regexBegin || current.regex, text, 0); >+ var result = _findMatch(current.regexBegin || current.regex, model, startIndex, endIndex); > if (result) { > matches.push({result: result, pattern: current}); > } >@@ -289,11 +375,11 @@ > > if (current.result.index < index) { > /* processing of another match has moved index beyond this match */ >- updateMatch(current, text, matches, index); >+ updateMatch(current, matches, model, index, endIndex); > continue; > } > >- var start = offset + current.result.index; >+ var start = /*offset +*/ current.result.index; > var contentStart = current.result.index; > var resultEnd = null; > >@@ -335,32 +421,32 @@ > > var lastIndex = contentStart; > while (!resultEnd) { >- var result = _findMatch(endRegex, text, lastIndex); >+ var result = _findMatch(resolvedEndRegex, model, lastIndex, endIndex); > if (!result) { > eolRegex.lastIndex = 0; >- result = eolRegex.exec(text); >+ result = _findMatch(eolRegex, model, /*startIndex*/endIndex, endIndex); // TODO verify that this works > } > var testBlock = new Block( > { > start: start, >- end: offset + result.index + result[0].length, >- contentStart: offset + contentStart, >- contentEnd: offset + result.index >+ end: /*offset +*/ result.index + result[0].length, >+ contentStart: /*offset +*/ contentStart, >+ contentEnd: /*offset +*/ result.index > }, > testPattern, > block.getStyler(), > model, > block); > var subBlocks = testBlock.getBlocks(); >- if (!subBlocks.length || subBlocks[subBlocks.length - 1].end <= (result.index + offset)) { >+ if (!subBlocks.length || subBlocks[subBlocks.length - 1].end <= (result.index /*+ offset*/)) { > resultEnd = testBlock; > } > lastIndex = result.index + result[0].length; > } > } > results.push(resultEnd); >- index = resultEnd.end - offset; >- updateMatch(current, text, matches, index); >+ index = resultEnd.end/*- offset*/; >+ updateMatch(current, matches, model, index, endIndex); > } > return results; > }; >@@ -372,7 +458,7 @@ > var subPatterns = block.getLinePatterns(); > if (subPatterns.length && block.pattern && block.pattern.pattern.name && block.pattern.pattern.name.indexOf("comment") === 0) { > var substyles = []; >- parse(baseModel.getText(block.contentStart, block.end), block.contentStart, block, substyles, true); >+ parse(baseModel, block.contentStart, block.end, block, substyles, true); > for (var i = 0; i < substyles.length; i++) { > if (substyles[i].style === "meta.annotation.task.todo") { > annotations.push(mAnnotations.AnnotationType.createAnnotation(annotationType, substyles[i].start, substyles[i].end, baseModel.getText(substyles[i].start, substyles[i].end))); >@@ -489,7 +575,7 @@ > this._enclosurePatterns = {}; > if (model) { > this._initPatterns(); >- this._subBlocks = computeBlocks(model, model.getText(this.start, this.end), this, this.start); >+ this._subBlocks = computeBlocks(model, this.start, this.end, this, 0/*, this.start*/); // TODO should the bounds be contentStart/contentEnd? > } > } > Block.prototype = { >@@ -730,9 +816,8 @@ > } > var block = this._findBlock(this._rootBlock, offset); > var lineIndex = model.getLineAtOffset(offset); >- var lineText = model.getLine(lineIndex); > var styles = []; >- parse(lineText, model.getLineStart(lineIndex), block, styles); >+ parse(model, model.getLineStart(lineIndex), model.getLineEnd(lineIndex), block, styles); > for (var i = 0; i < styles.length; i++) { > if (offset < styles[i].start) { > break; >@@ -871,6 +956,8 @@ > return result; > }, > _findMatchingBracket: function(model, block, offset) { >+ if (1) return -1; >+ > var lineIndex = model.getLineAtOffset(offset); > var lineEnd = model.getLineEnd(lineIndex); > var text = model.getText(offset, lineEnd); >@@ -978,28 +1065,28 @@ > _getPatternManager: function() { > return this.patternManager; > }, >- _getStyles: function(block, model, text, start) { >- if (model.getBaseModel) { >- start = model.mapOffset(start); >- } >- var end = start + text.length; >+ _getStyles: function(block, model, startIndex, endIndex) { >+// if (model.getBaseModel) { // TODO verify that this works with blocks folded >+// start = model.mapOffset(start); >+// } >+// var end = start + text.length; > > var styles = []; >- var offset = start, blocks = block.getBlocks(); >- var startIndex = this._binarySearch(blocks, start, true); >- for (var i = startIndex; i < blocks.length; i++) { >- if (blocks[i].start >= end) { break; } >+ var offset = startIndex, blocks = block.getBlocks(); >+ var blockStartIndex = this._binarySearch(blocks, startIndex, true); >+ for (var i = blockStartIndex; i < blocks.length; i++) { >+ if (blocks[i].start >= endIndex) { break; } > var blockStart = blocks[i].start; > var blockEnd = blocks[i].end; > if (offset < blockStart) { > /* content on that line that preceeds the start of the block */ >- parse(text.substring(offset - start, blockStart - start), offset, block, styles); >+ parse(model, offset/* - start*/, blockStart/* - start*/, block, styles); > } > var s = Math.max(offset, blockStart); > if (s === blockStart) { > /* currently at the block's "start" match, which specifies its style by either a capture or name */ > if (blocks[i].pattern.regexBegin) { >- var result = _findMatch(blocks[i].pattern.regexBegin, text.substring(s - start), 0); >+ var result = _findMatch(blocks[i].pattern.regexBegin, model, s - startIndex, model.getCharCount()); > if (result) { > /* the begin match is still valid */ > var captures = blocks[i].pattern.pattern.beginCaptures || blocks[i].pattern.pattern.captures; >@@ -1017,13 +1104,12 @@ > * Compute the end match now in order to determine the end-bound of the contained content, but do not add the > * end match's styles to the styles array until content styles have been computed so that ordering is preserved. > */ >- var e = Math.min(end, blockEnd); >+ var e = Math.min(endIndex, blockEnd); > var endStyles = []; > if (e === blockEnd) { > /* currently at the block's "end" match, which specifies its style by either a capture or name */ > if (blocks[i].pattern.regexEnd) { >- var testString = text.substring(e - offset - (blocks[i].end - blocks[i].contentEnd)); >- var result = _findMatch(blocks[i].pattern.regexEnd, testString, 0); >+ var result = _findMatch(blocks[i].pattern.regexEnd, model, e - offset - (blocks[i].end - blocks[i].contentEnd), model.getCharCount()); > if (result) { > /* the end match is still valid */ > var captures = blocks[i].pattern.pattern.endCaptures || blocks[i].pattern.pattern.captures; >@@ -1037,7 +1123,7 @@ > } > } > >- var blockSubstyles = this._getStyles(blocks[i], model, text.substring(s - start, e - start), s); >+ var blockSubstyles = this._getStyles(blocks[i], model, s, e); > var blockStyle = blocks[i].pattern.pattern.contentName || blocks[i].pattern.pattern.name; > if (blockStyle) { > /* >@@ -1061,9 +1147,9 @@ > styles = styles.concat(endStyles); > offset = blockEnd; > } >- if (offset < end) { >+ if (offset < endIndex) { > /* content on that line that follows the end of the block */ >- parse(text.substring(offset - start, end - start), offset, block, styles); >+ parse(model, offset, endIndex, block, styles); > } > if (model.getBaseModel) { > for (var j = 0; j < styles.length; j++) { >@@ -1084,10 +1170,11 @@ > if (e.textView === this.view) { > e.style = this._getLineStyle(e.lineIndex); > } >- e.ranges = this._getStyles(this._rootBlock, e.textView.getModel(), e.lineText, e.lineStart); >+ var model = e.textView.getModel(); >+ e.ranges = this._getStyles(this._rootBlock, model, e.lineStart, model.getLineEnd(e.lineIndex)); > e.ranges.forEach(function(current) { > if (current.style) { >- current.style = {styleClass: current.style.replace(/\./g, " ")}; >+ current.style = {styleClass: current.style.replace(/\./g, " ")}; //$NON-NLS-1$ > } > }); > if (this._isRenderingWhitespace()) { >@@ -1212,7 +1299,10 @@ > te = charCount; //TODO could it be smaller? > } > var text = baseModel.getText(ts, te), block; >- newBlocks = computeBlocks(baseModel, text, this._rootBlock, ts); >+var startTime = new Date().getTime(); >+ newBlocks = computeBlocks(baseModel, ts, te, this._rootBlock, 0/*ts*/); >+var endTime = new Date().getTime(); >+window.console.log(endTime - startTime); > } while (newBlocks.length && blocks.length && blockEnd < blockCount && newBlocks[newBlocks.length - 1].pattern.pattern.id !== blocks[blockEnd - 1].pattern.pattern.id); > > for (var i = blockStart; i < blocks.length; i++) {
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 430632
: 240990