private static void GetSourceLineInfoInner(IReadOnlyList <DbiModuleInfo> modules, MsfDirectory dir, PdbReader reader, IReadOnlyDictionary <int, string> names, uint token, uint iloffset, out string sourceFile, out int sourceLine, out int sourceColumn) { sourceFile = string.Empty; sourceLine = 0; sourceColumn = 0; foreach (DbiModuleInfo module in modules) { if (module.stream > 0) { DataStream stream = dir.Streams[module.stream]; using var bitsPool = new SafeArrayPool <byte>(stream.Length); byte[] bits = bitsPool.Array; stream.Read(reader, bits); if (TryGetManProcSym(bits, in module, token, out ManProcSym sym)) { GetLineNumberInformation(bits, in module, sym.off + iloffset, names, out sourceFile, out sourceLine, out sourceColumn); } } } }
// @@BPerfIgnoreAllocation@@ -- pages (not poolable due to MemoryMarshal), stream (meh), List<DataStream> lifetime extends method, dsPages lifetime on DataStream, Lifetime outside of scope for DataStream objects public MsfDirectory(PageAwarePdbReader reader, int pageSize, int directorySize, int[] directoryRoot) { int numPages = reader.PagesFromSize(directorySize); var pages = new int[numPages]; var buf = MemoryMarshal.Cast <int, byte>(pages); int offset = 0; int pagesPerPage = pageSize / 4; int pagesToGo = numPages; for (int i = 0; i < directoryRoot.Length; ++i) { int pagesInThisPage = pagesToGo <= pagesPerPage ? pagesToGo : pagesPerPage; reader.Seek(directoryRoot[i], 0); reader.Stream.Read(buf.Slice(offset, pagesInThisPage * 4)); pagesToGo -= pagesInThisPage; } byte[] buffer = default; int[] sizes = default; try { buffer = ArrayPool <byte> .Shared.Rent(directorySize); var stream = new DataStream(directorySize, pages); stream.Read(reader, buffer); offset = 0; int count = InterpretInt32(buffer, ref offset); try { // 4..n sizes = ArrayPool <int> .Shared.Rent(count); for (int i = 0; i < count; ++i) { sizes[i] = InterpretInt32(buffer, ref offset); } streams = new List <DataStream>(count); for (int i = 0; i < count; ++i) { if (sizes[i] <= 0) { streams.Add(new DataStream()); } else { int dsPagesCount = reader.PagesFromSize(sizes[i]); if (dsPagesCount > 0) { var dsPages = new int[dsPagesCount]; for (int j = 0; j < dsPagesCount; ++j) { dsPages[j] = InterpretInt32(buffer, ref offset); } streams.Add(new DataStream(sizes[i], dsPages)); } else { streams.Add(new DataStream(sizes[i], null)); } } } } finally { if (sizes != null) { ArrayPool <int> .Shared.Return(sizes); } } } finally { if (buffer != null) { ArrayPool <byte> .Shared.Return(buffer); } } }
public MsfDirectory(PdbReader reader, int pageSize, int directorySize, int[] directoryRoot) { var numPages = reader.PagesFromSize(directorySize); var pages = new int[numPages]; Span <byte> buf = MemoryMarshal.Cast <int, byte>(pages); var offset = 0; var pagesPerPage = pageSize / 4; var pagesToGo = numPages; foreach (var t in directoryRoot) { var pagesInThisPage = pagesToGo <= pagesPerPage ? pagesToGo : pagesPerPage; reader.Seek(t, 0); reader.Stream.Read(buf.Slice(offset, pagesInThisPage * 4)); pagesToGo -= pagesInThisPage; } using var buffer = new SafeArrayPool <byte>(directorySize); var stream = new DataStream(directorySize, pages); stream.Read(reader, buffer.Array); offset = 0; var count = InterpretInt32(buffer.Array, ref offset); using var sizesPool = new SafeArrayPool <int>(count); int[] sizes = sizesPool.Array; for (var i = 0; i < count; ++i) { sizes[i] = InterpretInt32(buffer.Array, ref offset); } this.streams = new DataStream[count]; for (var i = 0; i < count; ++i) { if (sizes[i] <= 0) { this.streams[i] = new DataStream(); } else { var dsPagesCount = reader.PagesFromSize(sizes[i]); if (dsPagesCount > 0) { var dsPages = new int[dsPagesCount]; for (var j = 0; j < dsPagesCount; ++j) { dsPages[j] = InterpretInt32(buffer.Array, ref offset); } this.streams[i] = new DataStream(sizes[i], dsPages); } else { this.streams[i] = new DataStream(sizes[i], Array.Empty <int>()); } } } }