Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitda7bce7

Browse files
authored
Change RandomAccess.Write* methods to be void-returning (#55490)
1 parentf787f38 commitda7bce7

File tree

15 files changed

+346
-244
lines changed

15 files changed

+346
-244
lines changed

‎src/libraries/System.IO.FileSystem/tests/RandomAccess/Mixed.Windows.cs‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,17 @@ static async Task Validate(SafeFileHandle handle, FileOptions options, bool[] sy
6262
{
6363
writeBuffer[0]=(byte)fileOffset;
6464

65-
Assert.Equal(writeBuffer.Length,syncWrite?RandomAccess.Write(handle,writeBuffer,fileOffset):awaitRandomAccess.WriteAsync(handle,writeBuffer,fileOffset));
65+
if(syncWrite)
66+
{
67+
RandomAccess.Write(handle,writeBuffer,fileOffset);
68+
}
69+
else
70+
{
71+
awaitRandomAccess.WriteAsync(handle,writeBuffer,fileOffset);
72+
}
73+
6674
Assert.Equal(writeBuffer.Length,syncRead?RandomAccess.Read(handle,readBuffer,fileOffset):awaitRandomAccess.ReadAsync(handle,readBuffer,fileOffset));
75+
6776
Assert.Equal(writeBuffer[0],readBuffer[0]);
6877

6978
fileOffset+=1;
@@ -116,8 +125,17 @@ static async Task Validate(SafeFileHandle handle, FileOptions options, bool[] sy
116125
writeBuffer_1[0]=(byte)fileOffset;
117126
writeBuffer_2[0]=(byte)(fileOffset+1);
118127

119-
Assert.Equal(writeBuffer_1.Length+writeBuffer_2.Length,syncWrite?RandomAccess.Write(handle,writeBuffers,fileOffset):awaitRandomAccess.WriteAsync(handle,writeBuffers,fileOffset));
128+
if(syncWrite)
129+
{
130+
RandomAccess.Write(handle,writeBuffers,fileOffset);
131+
}
132+
else
133+
{
134+
awaitRandomAccess.WriteAsync(handle,writeBuffers,fileOffset);
135+
}
136+
120137
Assert.Equal(writeBuffer_1.Length+writeBuffer_2.Length,syncRead?RandomAccess.Read(handle,readBuffers,fileOffset):awaitRandomAccess.ReadAsync(handle,readBuffers,fileOffset));
138+
121139
Assert.Equal(writeBuffer_1[0],readBuffer_1[0]);
122140
Assert.Equal(writeBuffer_2[0],readBuffer_2[0]);
123141

‎src/libraries/System.IO.FileSystem/tests/RandomAccess/NoBuffering.Windows.cs‎

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,16 @@ public async Task WriteUsingSingleBuffer(bool async)
118118
inttake=Math.Min(content.Length-total,bufferSize);
119119
content.AsSpan(total,take).CopyTo(buffer.GetSpan());
120120

121-
total+= async
122-
?awaitRandomAccess.WriteAsync(handle,buffer.Memory,fileOffset:total)
123-
:RandomAccess.Write(handle,buffer.GetSpan(),fileOffset:total);
121+
if(async)
122+
{
123+
awaitRandomAccess.WriteAsync(handle,buffer.Memory,fileOffset:total);
124+
}
125+
else
126+
{
127+
RandomAccess.Write(handle,buffer.GetSpan(),fileOffset:total);
128+
}
129+
130+
total+=buffer.Memory.Length;
124131
}
125132
}
126133

@@ -154,9 +161,16 @@ public async Task WriteAsyncUsingMultipleBuffers(bool async)
154161
content.AsSpan((int)total,bufferSize).CopyTo(buffer_1.GetSpan());
155162
content.AsSpan((int)total+bufferSize,bufferSize).CopyTo(buffer_2.GetSpan());
156163

157-
total+= async
158-
?awaitRandomAccess.WriteAsync(handle,buffers,fileOffset:total)
159-
:RandomAccess.Write(handle,buffers,fileOffset:total);
164+
if(async)
165+
{
166+
awaitRandomAccess.WriteAsync(handle,buffers,fileOffset:total);
167+
}
168+
else
169+
{
170+
RandomAccess.Write(handle,buffers,fileOffset:total);
171+
}
172+
173+
total+=buffer_1.Memory.Length+buffer_2.Memory.Length;
160174
}
161175
}
162176

‎src/libraries/System.IO.FileSystem/tests/RandomAccess/Write.cs‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ namespace System.IO.Tests
1010
publicclassRandomAccess_Write:RandomAccess_Base<int>
1111
{
1212
protectedoverrideintMethodUnderTest(SafeFileHandlehandle,byte[]bytes,longfileOffset)
13-
=>RandomAccess.Write(handle,bytes,fileOffset);
13+
{
14+
RandomAccess.Write(handle,bytes,fileOffset);
15+
returnbytes?.Length??0;
16+
}
1417

1518
[Theory]
1619
[MemberData(nameof(GetSyncAsyncOptions))]
@@ -24,11 +27,11 @@ public void ThrowsOnReadAccess(FileOptions options)
2427

2528
[Theory]
2629
[MemberData(nameof(GetSyncAsyncOptions))]
27-
publicvoidWriteUsingEmptyBufferReturnsZero(FileOptionsoptions)
30+
publicvoidWriteUsingEmptyBufferReturns(FileOptionsoptions)
2831
{
2932
using(SafeFileHandlehandle=File.OpenHandle(GetTestFilePath(),FileMode.Create,FileAccess.Write,options:options))
3033
{
31-
Assert.Equal(0,RandomAccess.Write(handle,Array.Empty<byte>(),fileOffset:0));
34+
RandomAccess.Write(handle,Array.Empty<byte>(),fileOffset:0);
3235
}
3336
}
3437

@@ -41,7 +44,7 @@ public void CanUseStackAllocatedMemory(FileOptions options)
4144

4245
using(SafeFileHandlehandle=File.OpenHandle(filePath,FileMode.Create,FileAccess.Write,options:options))
4346
{
44-
Assert.Equal(stackAllocated.Length,RandomAccess.Write(handle,stackAllocated,fileOffset:0));
47+
RandomAccess.Write(handle,stackAllocated,fileOffset:0);
4548
}
4649

4750
Assert.Equal(stackAllocated.ToArray(),File.ReadAllBytes(filePath));
@@ -58,17 +61,14 @@ public void WritesBytesFromGivenBufferToGivenFileAtGivenOffset(FileOptions optio
5861
using(SafeFileHandlehandle=File.OpenHandle(filePath,FileMode.CreateNew,FileAccess.Write,FileShare.None,options))
5962
{
6063
inttotal=0;
61-
intcurrent=0;
6264

6365
while(total!=fileSize)
6466
{
6567
Span<byte>buffer=content.AsSpan(total,Math.Min(content.Length-total,fileSize/4));
6668

67-
current=RandomAccess.Write(handle,buffer,fileOffset:total);
68-
69-
Assert.InRange(current,0,buffer.Length);
69+
RandomAccess.Write(handle,buffer,fileOffset:total);
7070

71-
total+=current;
71+
total+=buffer.Length;
7272
}
7373
}
7474

‎src/libraries/System.IO.FileSystem/tests/RandomAccess/WriteAsync.cs‎

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ namespace System.IO.Tests
1111
{
1212
[ActiveIssue("https://github.com/dotnet/runtime/issues/34582",TestPlatforms.Windows,TargetFrameworkMonikers.Netcoreapp,TestRuntimes.Mono)]
1313
[SkipOnPlatform(TestPlatforms.Browser,"async file IO is not supported on browser")]
14-
publicclassRandomAccess_WriteAsync:RandomAccess_Base<ValueTask<int>>
14+
publicclassRandomAccess_WriteAsync:RandomAccess_Base<ValueTask>
1515
{
16-
protectedoverrideValueTask<int>MethodUnderTest(SafeFileHandlehandle,byte[]bytes,longfileOffset)
16+
protectedoverrideValueTaskMethodUnderTest(SafeFileHandlehandle,byte[]bytes,longfileOffset)
1717
=>RandomAccess.WriteAsync(handle,bytes,fileOffset);
1818

1919
[Theory]
@@ -44,11 +44,11 @@ public async Task ThrowsOnReadAccess(FileOptions options)
4444

4545
[Theory]
4646
[MemberData(nameof(GetSyncAsyncOptions))]
47-
publicasyncTaskWriteUsingEmptyBufferReturnsZeroAsync(FileOptionsoptions)
47+
publicasyncTaskWriteUsingEmptyBufferReturnsAsync(FileOptionsoptions)
4848
{
4949
using(SafeFileHandlehandle=File.OpenHandle(GetTestFilePath(),FileMode.Create,FileAccess.Write,options:options))
5050
{
51-
Assert.Equal(0,awaitRandomAccess.WriteAsync(handle,Array.Empty<byte>(),fileOffset:0));
51+
awaitRandomAccess.WriteAsync(handle,Array.Empty<byte>(),fileOffset:0);
5252
}
5353
}
5454

@@ -63,17 +63,14 @@ public async Task WritesBytesFromGivenBufferToGivenFileAtGivenOffsetAsync(FileOp
6363
using(SafeFileHandlehandle=File.OpenHandle(filePath,FileMode.CreateNew,FileAccess.Write,FileShare.None,options))
6464
{
6565
inttotal=0;
66-
intcurrent=0;
6766

6867
while(total!=fileSize)
6968
{
7069
Memory<byte>buffer=content.AsMemory(total,Math.Min(content.Length-total,fileSize/4));
7170

72-
current=awaitRandomAccess.WriteAsync(handle,buffer,fileOffset:total);
71+
awaitRandomAccess.WriteAsync(handle,buffer,fileOffset:total);
7372

74-
Assert.InRange(current,0,buffer.Length);
75-
76-
total+=current;
73+
total+=buffer.Length;
7774
}
7875
}
7976

‎src/libraries/System.IO.FileSystem/tests/RandomAccess/WriteGather.cs‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ namespace System.IO.Tests
1212
publicclassRandomAccess_WriteGather:RandomAccess_Base<long>
1313
{
1414
protectedoverridelongMethodUnderTest(SafeFileHandlehandle,byte[]bytes,longfileOffset)
15-
=>RandomAccess.Write(handle,newReadOnlyMemory<byte>[]{bytes},fileOffset);
15+
{
16+
RandomAccess.Write(handle,newReadOnlyMemory<byte>[]{bytes},fileOffset);
17+
returnbytes?.Length??0;
18+
}
1619

1720
[Theory]
1821
[MemberData(nameof(GetSyncAsyncOptions))]
@@ -36,11 +39,11 @@ public void ThrowsOnReadAccess(FileOptions options)
3639

3740
[Theory]
3841
[MemberData(nameof(GetSyncAsyncOptions))]
39-
publicvoidWriteUsingEmptyBufferReturnsZero(FileOptionsoptions)
42+
publicvoidWriteUsingEmptyBufferReturns(FileOptionsoptions)
4043
{
4144
using(SafeFileHandlehandle=File.OpenHandle(GetTestFilePath(),FileMode.Create,FileAccess.Write,options:options))
4245
{
43-
Assert.Equal(0,RandomAccess.Write(handle,newReadOnlyMemory<byte>[]{Array.Empty<byte>()},fileOffset:0));
46+
RandomAccess.Write(handle,newReadOnlyMemory<byte>[]{Array.Empty<byte>()},fileOffset:0);
4447
}
4548
}
4649

@@ -55,15 +58,14 @@ public void WritesBytesFromGivenBuffersToGivenFileAtGivenOffset(FileOptions opti
5558
using(SafeFileHandlehandle=File.OpenHandle(filePath,FileMode.CreateNew,FileAccess.Write,FileShare.None,options))
5659
{
5760
longtotal=0;
58-
longcurrent=0;
5961

6062
while(total!=fileSize)
6163
{
6264
intfirstBufferLength=(int)Math.Min(content.Length-total,fileSize/4);
6365
Memory<byte>buffer_1=content.AsMemory((int)total,firstBufferLength);
6466
Memory<byte>buffer_2=content.AsMemory((int)total+firstBufferLength);
6567

66-
current=RandomAccess.Write(
68+
RandomAccess.Write(
6769
handle,
6870
newReadOnlyMemory<byte>[]
6971
{
@@ -73,9 +75,7 @@ public void WritesBytesFromGivenBuffersToGivenFileAtGivenOffset(FileOptions opti
7375
},
7476
fileOffset:total);
7577

76-
Assert.InRange(current,0,buffer_1.Length+buffer_2.Length);
77-
78-
total+=current;
78+
total+=buffer_1.Length+buffer_2.Length;
7979
}
8080
}
8181

@@ -94,7 +94,7 @@ public void DuplicatedBufferDuplicatesContent(FileOptions options)
9494

9595
using(SafeFileHandlehandle=File.OpenHandle(filePath,FileMode.Create,FileAccess.Write,options:options))
9696
{
97-
Assert.Equal(repeatCount,RandomAccess.Write(handle,buffers,fileOffset:0));
97+
RandomAccess.Write(handle,buffers,fileOffset:0);
9898
}
9999

100100
byte[]actualContent=File.ReadAllBytes(filePath);

‎src/libraries/System.IO.FileSystem/tests/RandomAccess/WriteGatherAsync.cs‎

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ namespace System.IO.Tests
1313
{
1414
[ActiveIssue("https://github.com/dotnet/runtime/issues/34582",TestPlatforms.Windows,TargetFrameworkMonikers.Netcoreapp,TestRuntimes.Mono)]
1515
[SkipOnPlatform(TestPlatforms.Browser,"async file IO is not supported on browser")]
16-
publicclassRandomAccess_WriteGatherAsync:RandomAccess_Base<ValueTask<long>>
16+
publicclassRandomAccess_WriteGatherAsync:RandomAccess_Base<ValueTask>
1717
{
18-
protectedoverrideValueTask<long>MethodUnderTest(SafeFileHandlehandle,byte[]bytes,longfileOffset)
18+
protectedoverrideValueTaskMethodUnderTest(SafeFileHandlehandle,byte[]bytes,longfileOffset)
1919
=>RandomAccess.WriteAsync(handle,newReadOnlyMemory<byte>[]{bytes},fileOffset);
2020

2121
[Theory]
@@ -56,11 +56,11 @@ public async Task ThrowsOnReadAccess(FileOptions options)
5656

5757
[Theory]
5858
[MemberData(nameof(GetSyncAsyncOptions))]
59-
publicasyncTaskWriteUsingEmptyBufferReturnsZeroAsync(FileOptionsoptions)
59+
publicasyncTaskWriteUsingEmptyBufferReturnsAsync(FileOptionsoptions)
6060
{
6161
using(SafeFileHandlehandle=File.OpenHandle(GetTestFilePath(),FileMode.Create,FileAccess.Write,options:options))
6262
{
63-
Assert.Equal(0,awaitRandomAccess.WriteAsync(handle,newReadOnlyMemory<byte>[]{Array.Empty<byte>()},fileOffset:0));
63+
awaitRandomAccess.WriteAsync(handle,newReadOnlyMemory<byte>[]{Array.Empty<byte>()},fileOffset:0);
6464
}
6565
}
6666

@@ -75,15 +75,14 @@ public async Task WritesBytesFromGivenBufferToGivenFileAtGivenOffsetAsync(FileOp
7575
using(SafeFileHandlehandle=File.OpenHandle(filePath,FileMode.CreateNew,FileAccess.Write,FileShare.None,options))
7676
{
7777
longtotal=0;
78-
longcurrent=0;
7978

8079
while(total!=fileSize)
8180
{
8281
intfirstBufferLength=(int)Math.Min(content.Length-total,fileSize/4);
8382
Memory<byte>buffer_1=content.AsMemory((int)total,firstBufferLength);
8483
Memory<byte>buffer_2=content.AsMemory((int)total+firstBufferLength);
8584

86-
current=awaitRandomAccess.WriteAsync(
85+
awaitRandomAccess.WriteAsync(
8786
handle,
8887
newReadOnlyMemory<byte>[]
8988
{
@@ -93,9 +92,7 @@ public async Task WritesBytesFromGivenBufferToGivenFileAtGivenOffsetAsync(FileOp
9392
},
9493
fileOffset:total);
9594

96-
Assert.InRange(current,0,buffer_1.Length+buffer_2.Length);
97-
98-
total+=current;
95+
total+=buffer_1.Length+buffer_2.Length;
9996
}
10097
}
10198

@@ -114,7 +111,7 @@ public async Task DuplicatedBufferDuplicatesContentAsync(FileOptions options)
114111

115112
using(SafeFileHandlehandle=File.OpenHandle(filePath,FileMode.Create,FileAccess.Write,options:options))
116113
{
117-
Assert.Equal(repeatCount,awaitRandomAccess.WriteAsync(handle,buffers,fileOffset:0));
114+
awaitRandomAccess.WriteAsync(handle,buffers,fileOffset:0);
118115
}
119116

120117
byte[]actualContent=File.ReadAllBytes(filePath);

‎src/libraries/System.Private.CoreLib/src/Microsoft/Win32/SafeHandles/SafeFileHandle.OverlappedValueTaskSource.Windows.cs‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,8 @@ internal static Exception GetIOError(int errorCode, string? path)
8686

8787
publicValueTaskSourceStatusGetStatus(shorttoken)=>_source.GetStatus(token);
8888
publicvoidOnCompleted(Action<object?>continuation,object?state,shorttoken,ValueTaskSourceOnCompletedFlagsflags)=>_source.OnCompleted(continuation,state,token,flags);
89-
voidIValueTaskSource.GetResult(shorttoken)=>GetResultAndRelease(token);
90-
intIValueTaskSource<int>.GetResult(shorttoken)=>GetResultAndRelease(token);
91-
92-
privateintGetResultAndRelease(shorttoken)
89+
voidIValueTaskSource.GetResult(shorttoken)=>GetResult(token);
90+
publicintGetResult(shorttoken)
9391
{
9492
try
9593
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp