Browse Source

Cache expressions (third attempt)

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@4767 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
David Srbecký 17 years ago
parent
commit
76c428f5e5
  1. 3
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/Process-StateControl.cs
  2. 14
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Expressions/ExpressionEvaluator.cs
  3. 1
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Expressions/ExpressionExtensionMethods.cs

3
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/Process-StateControl.cs

@ -5,6 +5,7 @@ @@ -5,6 +5,7 @@
// <version>$Revision$</version>
// </file>
using ICSharpCode.NRefactory.Ast;
using System;
using System.Collections.Generic;
@ -16,6 +17,7 @@ namespace Debugger @@ -16,6 +17,7 @@ namespace Debugger
{
internal bool TerminateCommandIssued = false;
internal Queue<Breakpoint> BreakpointHitEventQueue = new Queue<Breakpoint>();
internal Dictionary<INode, Value> CachedExpressions = new Dictionary<INode, Value>();
#region Events
@ -99,6 +101,7 @@ namespace Debugger @@ -99,6 +101,7 @@ namespace Debugger
if (action == DebuggeeStateAction.Clear) {
if (debuggeeState == null) throw new DebuggerException("Debugee state already cleared");
debuggeeState = null;
this.CachedExpressions.Clear();
}
}

14
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Expressions/ExpressionEvaluator.cs

@ -100,10 +100,17 @@ namespace Debugger @@ -100,10 +100,17 @@ namespace Debugger
public Value Evaluate(INode expression, bool permRef)
{
// Try to get the value from cache
// (the cache is cleared when the process is resumed)
Value val;
if (context.Process.CachedExpressions.TryGetValue(expression, out val)) {
if (val == null || !val.IsInvalid) {
return val;
}
}
Stopwatch watch = new Stopwatch();
watch.Start();
Value val;
try {
val = (Value)expression.AcceptVisitor(this, null);
if (val != null && permRef)
@ -117,6 +124,9 @@ namespace Debugger @@ -117,6 +124,9 @@ namespace Debugger
context.Process.TraceMessage("Evaluated: {0} in {1} ms total", expression.PrettyPrint(), watch.ElapsedMilliseconds);
}
// Add the result to cache
context.Process.CachedExpressions[expression] = val;
return val;
}

1
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Expressions/ExpressionExtensionMethods.cs

@ -58,6 +58,7 @@ namespace Debugger @@ -58,6 +58,7 @@ namespace Debugger
public static string PrettyPrint(this INode code)
{
if (code == null) return string.Empty;
CSharpOutputVisitor csOutVisitor = new CSharpOutputVisitor();
code.AcceptVisitor(csOutVisitor, null);
return csOutVisitor.Text;

Loading…
Cancel
Save