Browse Source

Optimization - if a property just returns a field value, do not evaluate the property but access the field directly.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2895 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
David Srbecký 18 years ago
parent
commit
a487ff25bf
  1. 1
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Debugger.Core.csproj
  2. 8
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/Eval.cs
  3. 63
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Metadata/MethodInfo.cs
  4. 26
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/CorDebug/ICorDebugCode.cs

1
src/AddIns/Misc/Debugger/Debugger.Core/Project/Debugger.Core.csproj

@ -313,6 +313,7 @@ @@ -313,6 +313,7 @@
<Compile Include="Src\Wrappers\CorDebug\ICorDebugChain.cs" />
<Compile Include="Src\Wrappers\CorDebug\ICorDebugChainEnum.cs" />
<Compile Include="Src\Wrappers\CorDebug\ICorDebugClass2.cs" />
<Compile Include="Src\Wrappers\CorDebug\ICorDebugCode.cs" />
<Compile Include="Src\Wrappers\CorDebug\ICorDebugFrame.cs" />
<Compile Include="Src\Wrappers\CorDebug\ICorDebugFrameEnum.cs" />
<Compile Include="Src\Wrappers\CorDebug\ICorDebugGenericValue.cs" />

8
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/Eval.cs

@ -106,14 +106,18 @@ namespace Debugger @@ -106,14 +106,18 @@ namespace Debugger
return InvokeMethod(MethodInfo.GetFromName(process, type, name, args.Length), thisValue, args);
}
#endregion
/// <summary> Synchronously calls a function and returns its return value </summary>
public static Value InvokeMethod(MethodInfo method, Value thisValue, Value[] args)
{
if (method.BackingField != null) {
method.Process.TraceMessage("Using backing field for " + method.FullName);
return Value.GetMemberValue(thisValue, method.BackingField, args);
}
return AsyncInvokeMethod(method, thisValue, args).EvaluateNow();
}
#endregion
public static Eval AsyncInvokeMethod(MethodInfo method, Value thisValue, Value[] args)
{
return new Eval(

63
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Metadata/MethodInfo.cs

@ -20,6 +20,7 @@ namespace Debugger.MetaData @@ -20,6 +20,7 @@ namespace Debugger.MetaData
public class MethodInfo: MemberInfo
{
MethodProps methodProps;
FieldInfo backingField;
/// <summary> Gets the name of this method </summary>
public override string Name {
@ -28,6 +29,10 @@ namespace Debugger.MetaData @@ -28,6 +29,10 @@ namespace Debugger.MetaData
}
}
internal FieldInfo BackingField {
get { return backingField; }
}
/// <summary> Gets a value indicating whether this method is private </summary>
public override bool IsPrivate {
get {
@ -75,6 +80,64 @@ namespace Debugger.MetaData @@ -75,6 +80,64 @@ namespace Debugger.MetaData
internal MethodInfo(DebugType declaringType, MethodProps methodProps):base (declaringType)
{
this.methodProps = methodProps;
this.backingField = GetBackingField();
}
// Is this method in form 'return this.field;'?
FieldInfo GetBackingField()
{
if (this.IsStatic) return null;
if (this.ParameterCount != 0) return null;
ICorDebugCode corCode;
try {
corCode = this.CorFunction.ILCode;
} catch {
return null;
}
if (corCode == null) return null;
if (corCode.Size != 12) return null;
byte[] code = corCode.GetCode();
if (code == null) return null;
/*
string codeTxt = "";
foreach(byte b in code) {
codeTxt += b.ToString("X2") + " ";
}
this.Process.TraceMessage("Code of " + Name + ": " + codeTxt);
*/
if (code[00] == 0x00 && // nop
code[01] == 0x02 && // ldarg.0
code[02] == 0x7B && // ldfld
code[06] == 0x04 && // <field token>
code[07] == 0x0A && // stloc.0
code[08] == 0x2B && // br.s
code[09] == 0x00 && // offset+00
code[10] == 0x06 && // ldloc.0
code[11] == 0x2A) // ret
{
uint token =
((uint)code[06] << 24) +
((uint)code[05] << 16) +
((uint)code[04] << 8) +
((uint)code[03]);
// this.Process.TraceMessage("Token: " + token.ToString("x"));
MemberInfo member = this.DeclaringType.GetMember(token);
if (member == null) return null;
if (!(member is FieldInfo)) return null;
this.Process.TraceMessage(string.Format("Found backing field for {0}: {1}", this.FullName, member.Name));
return (FieldInfo)member;
}
return null;
}
/// <summary>

26
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/CorDebug/ICorDebugCode.cs

@ -0,0 +1,26 @@ @@ -0,0 +1,26 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="David Srbecký" email="dsrbecky@gmail.com"/>
// <version>$Revision$</version>
// </file>
#pragma warning disable 1591
namespace Debugger.Wrappers.CorDebug
{
using System;
public partial class ICorDebugCode
{
public unsafe byte[] GetCode()
{
if (this.IsIL == 0) return null;
byte[] code = new byte[this.Size];
fixed(void* pCode = code) {
this.GetCode(0, (uint)code.Length, (uint)code.Length, new IntPtr(pCode));
}
return code;
}
}
}
Loading…
Cancel
Save