-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Remove incorrect ExceptionArgument.length for ArgumentOutOfRangeException in MemoryMarshal
#105475
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove incorrect ExceptionArgument.length for ArgumentOutOfRangeException in MemoryMarshal
#105475
Conversation
…ception` in `MemoryMarshal` Arguably an `ArgumentException` should be thrown in these case, not `ArgumentOutOfRangeException`, but it would be a breaking change to change this.
|
Tagging subscribers to this area: @dotnet/interop-contrib |
|
While I know it's not perfect, I prefer it the way it is: the caller is told that the length is the problem. In an ideal world, maybe it would be span.Length, but I'd rather just leave things as they are. |
In the case of The documentation for ArgumentOutOfRangeException states: "The exception that is thrown when the value of an argument is outside the allowable range of values as defined by the invoked method." In this case it is the property of the argument that is out of range. Perhaps the documentation should be updated? |
What else would the "length" be other than "source.Length"? |
I mean what else would the |
It tells you what's wrong with it. The length is wrong. |
I tend to agree. I don't think this clarifies all that much and since it is a breaking change I don't think it is appropriate. |
I hadn't considered that changing the But the |
The actual name of the argument is
sourceorspantherefore this is incorrect.Arguably an
ArgumentExceptionshould be thrown in these case, notArgumentOutOfRangeException, but it would be a breaking change to change this.Just remove the
ExceptionArgumentlike inSpan.Slice.Relatively large diff improvements as a result:
-34 (-15.32 % of base) - System.IO.Hashing.XxHash32+State:Complete(int,System.ReadOnlySpan`1[ubyte]):uint:this
G_M56174_IG01: push rbp mov rbp, rsp ;; size=4 bbWeight=1 PerfScore 1.25 G_M56174_IG02: cmp byte ptr [rdi+0x14], 0 je SHORT G_M56174_IG04 ;; size=6 bbWeight=1 PerfScore 4.00 G_M56174_IG03: mov eax, dword ptr [rdi] rol eax, 1 mov r8d, dword ptr [rdi+0x04] rol r8d, 7 add eax, r8d mov r8d, dword ptr [rdi+0x08] rol r8d, 12 add eax, r8d mov r8d, dword ptr [rdi+0x0C] rol r8d, 18 add eax, r8d jmp SHORT G_M56174_IG05 align [5 bytes for IG06] ;; size=44 bbWeight=0.50 PerfScore 6.62 G_M56174_IG04: mov eax, dword ptr [rdi+0x10] ;; size=3 bbWeight=0.50 PerfScore 1.00 G_M56174_IG05: add eax, esi cmp ecx, 4 jl SHORT G_M56174_IG07 ;; size=7 bbWeight=1 PerfScore 1.50 G_M56174_IG06: cmp ecx, 4 - jl G_M56174_IG12 + jl SHORT G_M56174_IG11 imul edi, dword ptr [rdx], 0xD1FFAB1E add eax, edi rol eax, 17 imul eax, eax, 0xD1FFAB1E cmp ecx, 4 jb SHORT G_M56174_IG11 add rdx, 4 add ecx, -4 cmp ecx, 4 jge SHORT G_M56174_IG06 - ;; size=43 bbWeight=4 PerfScore 48.00 + ;; size=39 bbWeight=4 PerfScore 48.00 G_M56174_IG07: xor edi, edi test ecx, ecx jle SHORT G_M56174_IG09 - align [15 bytes for IG08] - ;; size=21 bbWeight=1 PerfScore 1.75 + align [3 bytes for IG08] + ;; size=9 bbWeight=1 PerfScore 1.75 G_M56174_IG08: movzx rsi, byte ptr [rdx+rdi] imul esi, esi, 0xD1FFAB1E add esi, eax rol esi, 11 imul eax, esi, 0xD1FFAB1E inc edi cmp edi, ecx jl SHORT G_M56174_IG08 ;; size=28 bbWeight=4 PerfScore 33.00 G_M56174_IG09: mov ecx, eax shr ecx, 15 xor ecx, eax imul eax, ecx, 0xD1FFAB1E mov ecx, eax shr ecx, 13 xor ecx, eax imul eax, ecx, 0xD1FFAB1E mov ecx, eax shr ecx, 16 xor eax, ecx ;; size=33 bbWeight=1 PerfScore 7.00 G_M56174_IG10: pop rbp ret ;; size=2 bbWeight=1 PerfScore 1.50 G_M56174_IG11: mov rax, 0xD1FFAB1E ; code for System.ThrowHelper:ThrowArgumentOutOfRangeException() call [rax]System.ThrowHelper:ThrowArgumentOutOfRangeException() int3 ;; size=13 bbWeight=0 PerfScore 0.00 -G_M56174_IG12: - mov edi, 40 - mov rax, 0xD1FFAB1E ; code for System.ThrowHelper:ThrowArgumentOutOfRangeException(int) - call [rax]System.ThrowHelper:ThrowArgumentOutOfRangeException(int) - int3 - ;; size=18 bbWeight=0 PerfScore 0.00 -; Total bytes of code 222, prolog size 4, PerfScore 105.62, instruction count 65, allocated bytes for code 222 (MethodHash=15592491) for method System.IO.Hashing.XxHash32+State:Complete(int,System.ReadOnlySpan`1[ubyte]):uint:this (FullOpts) +; Total bytes of code 188, prolog size 4, PerfScore 105.62, instruction count 61, allocated bytes for code 188 (MethodHash=15592491) for method System.IO.Hashing.XxHash32+State:Complete(int,System.ReadOnlySpan`1[ubyte]):uint:this (FullOpts)MihuBot/runtime-utils#557