10
10
using System ;
11
11
using MS . Internal ;
12
12
using MS . Win32 ;
13
+ using System . Buffers ;
13
14
using System . Reflection ;
14
15
using System . Collections ;
15
16
using System . Diagnostics ;
@@ -27,7 +28,7 @@ namespace System.Windows.Media
27
28
internal struct StreamDescriptor
28
29
{
29
30
internal delegate void Dispose ( ref StreamDescriptor pSD ) ;
30
- internal delegate int Read ( ref StreamDescriptor pSD , [ MarshalAs ( UnmanagedType . LPArray , SizeParamIndex = 2 ) , Out ] byte [ ] buffer , uint cb , out uint cbRead ) ;
31
+ internal delegate int Read ( ref StreamDescriptor pSD , IntPtr buffer , uint cb , out uint cbRead ) ;
31
32
32
33
internal unsafe delegate int Seek ( ref StreamDescriptor pSD , long offset , uint origin , long * plibNewPostion ) ;
33
34
internal delegate int Stat ( ref StreamDescriptor pSD , out System . Runtime . InteropServices . ComTypes . STATSTG statstg , uint grfStatFlag ) ;
@@ -236,7 +237,7 @@ public int CopyTo(IntPtr /* IStream */ pstm, long cb, out long cbRead, out long
236
237
237
238
uint read = 0 ;
238
239
239
- hr = Read ( buffer , toRead , out read ) ;
240
+ hr = Read ( buffer . AsSpan ( 0 , ( int ) toRead ) , out read ) ;
240
241
241
242
if ( read == 0 )
242
243
{
@@ -289,7 +290,7 @@ public int LockRegion(long libOffset, long cb, uint dwLockType)
289
290
return NativeMethods . E_NOTIMPL ;
290
291
}
291
292
292
- public int Read ( byte [ ] buffer , uint cb , out uint cbRead )
293
+ public int Read ( Span < byte > buffer , out uint cbRead )
293
294
{
294
295
cbRead = 0 ;
295
296
@@ -300,7 +301,7 @@ public int Read(byte[] buffer, uint cb, out uint cbRead)
300
301
Verify ( ) ;
301
302
ActualizeVirtualPosition ( ) ;
302
303
303
- cbRead = ( uint ) dataStream . Read ( buffer , 0 , ( int ) cb ) ;
304
+ cbRead = ( uint ) dataStream . Read ( buffer ) ;
304
305
}
305
306
catch ( Exception e )
306
307
{
@@ -596,9 +597,10 @@ internal static int LockRegion(ref StreamDescriptor pSD, long libOffset, long cb
596
597
return ( StreamAsIStream . FromSD ( ref pSD ) ) . LockRegion ( libOffset , cb , dwLockType ) ;
597
598
}
598
599
599
- internal static int Read ( ref StreamDescriptor pSD , byte [ ] buffer , uint cb , out uint cbRead )
600
+ internal static unsafe int Read ( ref StreamDescriptor pSD , IntPtr buffer , uint cb , out uint cbRead )
600
601
{
601
- return ( StreamAsIStream . FromSD ( ref pSD ) ) . Read ( buffer , cb , out cbRead ) ;
602
+ var span = new Span < byte > ( buffer . ToPointer ( ) , ( int ) cb ) ;
603
+ return ( StreamAsIStream . FromSD ( ref pSD ) ) . Read ( span , out cbRead ) ;
602
604
}
603
605
604
606
internal static int Revert ( ref StreamDescriptor pSD )
0 commit comments