Skip to content

Commit

Permalink
Address feedbacks from review
Browse files Browse the repository at this point in the history
  • Loading branch information
hez2010 committed Mar 16, 2022
1 parent 866bcba commit b92ad36
Showing 1 changed file with 16 additions and 112 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -388,24 +388,11 @@ public unsafe sealed record SymUnmanagedNamespaceRcw(IntPtr Inst) : ISymUnmanage
public int GetName(int bufferLength, out int count, char[] name)
{
var func = (delegate* unmanaged<IntPtr, int, int*, char*, int>)(*(*(void***)Inst + 3));
int hr;

fixed (int* countPtr = &count)
fixed (char* namePtr = name)
{
if (name == null)
{
hr = func(Inst, bufferLength, countPtr, null);
}
else
{
fixed (char* namePtr = name)
{
hr = func(Inst, bufferLength, countPtr, namePtr);
}
}
return func(Inst, bufferLength, countPtr, namePtr);
}

return hr;
}

public int GetNamespaces(int bufferLength, out int count, ISymUnmanagedNamespace[] namespaces)
Expand Down Expand Up @@ -514,49 +501,23 @@ public unsafe sealed record SymUnmanagedVariableRcw(IntPtr Inst) : ISymUnmanaged
public int GetName(int bufferLength, out int count, char[] name)
{
var func = (delegate* unmanaged<IntPtr, int, int*, char*, int>)(*(*(void***)Inst + 3));
int hr;

fixed (int* countPtr = &count)
fixed (char* namePtr = name)
{
if (name == null)
{
hr = func(Inst, bufferLength, countPtr, null);
}
else
{
fixed (char* namePtr = name)
{
hr = func(Inst, bufferLength, countPtr, namePtr);
}
}
return func(Inst, bufferLength, countPtr, namePtr);
}

return hr;
}

public int GetAttributes(out int attributes) => SingleByRefIntWrapper(4, out attributes);

public int GetSignature(int bufferLength, out int count, byte[] signature)
{
var func = (delegate* unmanaged<IntPtr, int, int*, byte*, int>)(*(*(void***)Inst + 5));
int hr;

fixed (int* countPtr = &count)
fixed (byte* signaturePtr = signature)
{
if (signature == null)
{
hr = func(Inst, bufferLength, countPtr, null);
}
else
{
fixed (byte* signaturePtr = signature)
{
hr = func(Inst, bufferLength, countPtr, signaturePtr);
}
}
return func(Inst, bufferLength, countPtr, signaturePtr);
}

return hr;
}

public int GetAddressKind(out int kind) => SingleByRefIntWrapper(6, out kind);
Expand Down Expand Up @@ -797,38 +758,21 @@ public unsafe record SymUnmanagedDocumentRcw(IntPtr Inst) : ISymUnmanagedDocumen
public int GetUrl(int bufferLength, out int count, char[] url)
{
var func = (delegate* unmanaged<IntPtr, int, int*, char*, int>)(*(*(void***)Inst + 3));
int hr;

fixed (int* countPtr = &count)
fixed (char* urlPtr = url)
{
if (url == null)
{
hr = func(Inst, bufferLength, countPtr, null);
}
else
{
fixed (char* urlPtr = url)
{
hr = func(Inst, bufferLength, countPtr, urlPtr);
}
}
return func(Inst, bufferLength, countPtr, urlPtr);
}

return hr;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private int SingleByRefGuidWrapper(int methodSolt, ref Guid guid)
{
var func = (delegate* unmanaged<IntPtr, Guid*, int>)(*(*(void***)Inst + methodSolt));
int hr;

fixed (Guid* guidPtr = &guid)
{
hr = func(Inst, guidPtr);
return func(Inst, guidPtr);
}

return hr;
}

public int GetDocumentType(ref Guid documentType) => SingleByRefGuidWrapper(4, ref documentType);
Expand All @@ -839,24 +783,11 @@ private int SingleByRefGuidWrapper(int methodSolt, ref Guid guid)
public int GetChecksum(int bufferLength, out int count, byte[] checksum)
{
var func = (delegate* unmanaged<IntPtr, int, int*, byte*, int>)(*(*(void***)Inst + 8));
int hr;

fixed (int* countPtr = &count)
fixed (byte* checksumPtr = checksum)
{
if (checksum == null)
{
hr = func(Inst, bufferLength, countPtr, null);
}
else
{
fixed (byte* checksumPtr = checksum)
{
hr = func(Inst, bufferLength, countPtr, checksumPtr);
}
}
return func(Inst, bufferLength, countPtr, checksumPtr);
}

return hr;
}

public int FindClosestLine(int line, out int closestLine)
Expand Down Expand Up @@ -889,24 +820,11 @@ public int GetSourceLength(out int length)
public int GetSourceRange(int startLine, int startColumn, int endLine, int endColumn, int bufferLength, out int count, byte[] source)
{
var func = (delegate* unmanaged<IntPtr, int, int, int, int, int, int*, byte*, int>)(*(*(void***)Inst + 12));
int hr;

fixed (int* countPtr = &count)
fixed (byte* sourcePtr = source)
{
if (source == null)
{
hr = func(Inst, startLine, startColumn, endLine, endColumn, bufferLength, countPtr, null);
}
else
{
fixed (byte* sourcePtr = source)
{
hr = func(Inst, startLine, startColumn, endLine, endColumn, bufferLength, countPtr, sourcePtr);
}
}
return func(Inst, startLine, startColumn, endLine, endColumn, bufferLength, countPtr, sourcePtr);
}

return hr;
}

public void Dispose()
Expand Down Expand Up @@ -1009,30 +927,18 @@ public int GetRanges(ISymUnmanagedDocument document, int line, int column, int b
{
var func = (delegate* unmanaged<IntPtr, IntPtr, int, int, int, int*, int*, int>)(*(*(void***)Inst + 8));
var handle = GCHandle.Alloc(document, GCHandleType.Pinned);
int hr;
try
{
fixed (int* countPtr = &count)
fixed (int* rangesPtr = ranges)
{
if (ranges == null)
{
hr = func(Inst, handle.AddrOfPinnedObject(), line, column, bufferLength, countPtr, null);
}
else
{
fixed (int* rangesPtr = ranges)
{
hr = func(Inst, handle.AddrOfPinnedObject(), line, column, bufferLength, countPtr, rangesPtr);
}
}
return func(Inst, handle.AddrOfPinnedObject(), line, column, bufferLength, countPtr, rangesPtr);
}
}
finally
{
handle.Free();
}

return hr;
}

public int GetParameters(int bufferLength, out int count, ISymUnmanagedVariable[] parameters)
Expand Down Expand Up @@ -1082,21 +988,19 @@ public int GetSourceStartEnd(ISymUnmanagedDocument[] documents, int[] lines, int
{
var func = (delegate* unmanaged<IntPtr, IntPtr*, int*, int*, bool*, int>)(*(*(void***)Inst + 11));
var handle = GCHandle.Alloc(documents, GCHandleType.Pinned);
int hr;
try
{
fixed (int* linesPtr = lines)
fixed (int* columnsPtr = columns)
fixed (bool* definedPtr = &defined)
{
hr = func(Inst, (IntPtr*)handle.AddrOfPinnedObject(), linesPtr, columnsPtr, definedPtr);
return func(Inst, (IntPtr*)handle.AddrOfPinnedObject(), linesPtr, columnsPtr, definedPtr);
}
}
finally
{
handle.Free();
}
return hr;
}

public int GetSequencePoints(int bufferLength, out int count, int[] offsets, ISymUnmanagedDocument[] documents, int[] startLines, int[] startColumns, int[] endLines, int[] endColumns)
Expand Down

0 comments on commit b92ad36

Please sign in to comment.