System.Numerics.BigInteger: use LastIndexOfAnyExcept (when relevant) #84855
Description
Description
System.Numerics.BigInteger
has a number of methods that look for the first zero (or first non-zero) element. This is usually done by looping through the span/array. It seems that most of them can be rewritten by Span.LastIndexOfAnyExcept()
(or similar methods) - this method can be faster than plain loop. Isolated tests show improvement up to 8 times on modern x64 (but any distinct case need clarification).
Click here to expand and show examples
runtime/src/libraries/System.Runtime.Numerics/src/System/Numerics/BigInteger.cs
Lines 1387 to 1390 in bed0ec0
runtime/src/libraries/System.Runtime.Numerics/src/System/Numerics/BigInteger.cs
Lines 1545 to 1550 in bed0ec0
runtime/src/libraries/System.Runtime.Numerics/src/System/Numerics/BigInteger.cs
Lines 3093 to 3101 in bed0ec0
runtime/src/libraries/System.Runtime.Numerics/src/System/Numerics/BigInteger.cs
Lines 3540 to 3544 in bed0ec0
runtime/src/libraries/System.Runtime.Numerics/src/System/Numerics/BigInteger.cs
Lines 3599 to 3606 in bed0ec0
runtime/src/libraries/System.Runtime.Numerics/src/System/Numerics/BigInteger.cs
Lines 3840 to 3847 in bed0ec0
May be I miss some of them. May be some of them shouldn't use span memory extension methods.
Configuration
Current main branch
Regression?
No
Data
Will be provided
Analysis
Will be provided
Activity