Browse Source

optimized IHighlightedLineBuilder creation

pull/23/head
Siegfried Pammer 14 years ago
parent
commit
9d0834ac82
  1. 11
      src/AddIns/Misc/SearchAndReplace/Project/Engine/SearchManager.cs
  2. 6
      src/Main/Base/Project/Src/Editor/Search/SearchResultsPad.cs
  3. 19
      src/Main/Base/Project/Src/Services/RefactoringService/FindReferencesAndRenameHelper.cs

11
src/AddIns/Misc/SearchAndReplace/Project/Engine/SearchManager.cs

@ -92,6 +92,7 @@ namespace SearchAndReplace
IEnumerable<FileName> fileList; IEnumerable<FileName> fileList;
IProgressMonitor monitor; IProgressMonitor monitor;
int count; int count;
double oneStep;
CancellationTokenSource cts; CancellationTokenSource cts;
public bool UseParallel { get; set; } public bool UseParallel { get; set; }
@ -117,6 +118,7 @@ namespace SearchAndReplace
delegate { delegate {
var list = fileList.ToList(); var list = fileList.ToList();
this.count = list.Count; this.count = list.Count;
this.oneStep = 1.0 / this.count;
monitor.CancellationToken.ThrowIfCancellationRequested(); monitor.CancellationToken.ThrowIfCancellationRequested();
cts.Token.ThrowIfCancellationRequested(); cts.Token.ThrowIfCancellationRequested();
Parallel.ForEach(list, new ParallelOptions { CancellationToken = monitor.CancellationToken, MaxDegreeOfParallelism = Environment.ProcessorCount }, fileName => SearchFile(fileName, strategy, monitor.CancellationToken)); Parallel.ForEach(list, new ParallelOptions { CancellationToken = monitor.CancellationToken, MaxDegreeOfParallelism = Environment.ProcessorCount }, fileName => SearchFile(fileName, strategy, monitor.CancellationToken));
@ -126,6 +128,7 @@ namespace SearchAndReplace
} else { } else {
var list = fileList.ToList(); var list = fileList.ToList();
this.count = list.Count; this.count = list.Count;
this.oneStep = 1.0 / this.count;
monitor.CancellationToken.ThrowIfCancellationRequested(); monitor.CancellationToken.ThrowIfCancellationRequested();
cts.Token.ThrowIfCancellationRequested(); cts.Token.ThrowIfCancellationRequested();
foreach (var file in list) { foreach (var file in list) {
@ -166,14 +169,18 @@ namespace SearchAndReplace
var highlighting = HighlightingManager.Instance.GetDefinitionByExtension(Path.GetExtension(fileName)); var highlighting = HighlightingManager.Instance.GetDefinitionByExtension(Path.GetExtension(fileName));
if (highlighting != null) if (highlighting != null)
highlighter = new DocumentHighlighter(document, highlighting.MainRuleSet); highlighter = new DocumentHighlighter(document, highlighting.MainRuleSet);
else
highlighter = null;
} }
var start = document.GetLocation(result.Offset).ToLocation(); var start = document.GetLocation(result.Offset).ToLocation();
var end = document.GetLocation(result.Offset + result.Length).ToLocation(); var end = document.GetLocation(result.Offset + result.Length).ToLocation();
var builder = SearchResultsPad.CreateInlineBuilder(start, end, document, highlighter);
var match = new SearchResultMatch(fileName, start, end, result.Offset, result.Length, builder);
lock (observer) lock (observer)
observer.OnNext(new SearchResultMatch(fileName, start, end, result.Offset, result.Length, SearchResultsPad.CreateInlineBuilder(start, end, document, Path.GetExtension(fileName)))); observer.OnNext(match);
} }
lock (monitor) lock (monitor)
monitor.Progress += 1.0 / count; monitor.Progress += oneStep;
} }
} }

6
src/Main/Base/Project/Src/Editor/Search/SearchResultsPad.cs

@ -147,15 +147,11 @@ namespace ICSharpCode.SharpDevelop.Editor.Search
return new DummySearchResult { Text = title }; return new DummySearchResult { Text = title };
} }
public static HighlightedInlineBuilder CreateInlineBuilder(Location startPosition, Location endPosition, TextDocument document, string fileExtension) public static HighlightedInlineBuilder CreateInlineBuilder(Location startPosition, Location endPosition, TextDocument document, IHighlighter highlighter)
{ {
if (startPosition.Line >= 1 && startPosition.Line <= document.LineCount) { if (startPosition.Line >= 1 && startPosition.Line <= document.LineCount) {
var matchedLine = document.GetLineByNumber(startPosition.Line); var matchedLine = document.GetLineByNumber(startPosition.Line);
HighlightedInlineBuilder inlineBuilder = new HighlightedInlineBuilder(document.GetText(matchedLine)); HighlightedInlineBuilder inlineBuilder = new HighlightedInlineBuilder(document.GetText(matchedLine));
var def = HighlightingManager.Instance.GetDefinitionByExtension(fileExtension);
if (def == null)
return inlineBuilder;
var highlighter = new DocumentHighlighter(document, def.MainRuleSet);
if (highlighter != null) { if (highlighter != null) {
HighlightedLine highlightedLine = highlighter.HighlightLine(startPosition.Line); HighlightedLine highlightedLine = highlighter.HighlightLine(startPosition.Line);
int startOffset = highlightedLine.DocumentLine.Offset; int startOffset = highlightedLine.DocumentLine.Offset;

19
src/Main/Base/Project/Src/Services/RefactoringService/FindReferencesAndRenameHelper.cs

@ -4,8 +4,10 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using System.Text; using System.Text;
using ICSharpCode.AvalonEdit.Document; using ICSharpCode.AvalonEdit.Document;
using ICSharpCode.AvalonEdit.Highlighting;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.NRefactory; using ICSharpCode.NRefactory;
using ICSharpCode.SharpDevelop.Dom; using ICSharpCode.SharpDevelop.Dom;
@ -372,11 +374,24 @@ namespace ICSharpCode.SharpDevelop.Refactoring
{ {
if (list == null) return; if (list == null) return;
List<SearchResultMatch> results = new List<SearchResultMatch>(list.Count); List<SearchResultMatch> results = new List<SearchResultMatch>(list.Count);
TextDocument document = null;
FileName fileName = null;
IHighlighter highlighter = null;
foreach (Reference r in list) { foreach (Reference r in list) {
var document = new TextDocument(DocumentUtilitites.GetTextSource(ParserService.GetParseableFileContent(r.FileName))); var f = new FileName(r.FileName);
if (document == null || !f.Equals(fileName)) {
document = new TextDocument(DocumentUtilitites.GetTextSource(ParserService.GetParseableFileContent(r.FileName)));
fileName = new FileName(r.FileName);
var def = HighlightingManager.Instance.GetDefinitionByExtension(Path.GetExtension(r.FileName));
if (def != null)
highlighter = new DocumentHighlighter(document, def.MainRuleSet);
else
highlighter = null;
}
var start = document.GetLocation(r.Offset).ToLocation(); var start = document.GetLocation(r.Offset).ToLocation();
var end = document.GetLocation(r.Offset + r.Length).ToLocation(); var end = document.GetLocation(r.Offset + r.Length).ToLocation();
SearchResultMatch res = new SearchResultMatch(new FileName(r.FileName), start, end, r.Offset, r.Length, SearchResultsPad.CreateInlineBuilder(start, end, document, Path.GetExtension(r.FileName))); var builder = SearchResultsPad.CreateInlineBuilder(start, end, document, highlighter);
SearchResultMatch res = new SearchResultMatch(fileName, start, end, r.Offset, r.Length, builder);
results.Add(res); results.Add(res);
} }
SearchResultsPad.Instance.ShowSearchResults(title, results); SearchResultsPad.Instance.ShowSearchResults(title, results);

Loading…
Cancel
Save