Commit ceef11f
[release/7.0-rc1] Optimized string.Replace(char, char) (#74047)
* Optimized string.Replace(char, char) vector code path
* Optimized code pathes even further
* Do vectorized operation at the end of the string only once
When the remaining length is a multiple of the vector size, then the remainder is processed twice. This is redundant, and not needed.
This commit changes that, so that the remainder is processed only once when the remaining elements match.
* Don't use trick for collapsed epilogs
Cf. #67049 (comment)
* Handle remainder vectorized even if remainingLength <= Vector<ushort>.Count and added tests for this
* Introduce (internal) Vector.LoadUnsafe and Vector.StoreUnsafe and use it in string.Replace(char, char)
* Avoid Unsafe.As<char, ushort> reinterpret casts by introducing string.GetRawStringDataAsUshort() internal method
* Fixed copy/paste error (from local dev to repo)
* PR Feedback
* Fixed bug and added tests for this
* Make condition about lengthToExamine clearer as suggested
Co-authored-by: Günther Foidl <gue@korporal.at>1 parent 8baff7d commit ceef11f
File tree
4 files changed
+71
-25
lines changed- src/libraries
- Common/tests/Tests/System
- System.Private.CoreLib/src/System
- Numerics
4 files changed
+71
-25
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4697 | 4697 | | |
4698 | 4698 | | |
4699 | 4699 | | |
4700 | | - | |
| 4700 | + | |
4701 | 4701 | | |
| 4702 | + | |
| 4703 | + | |
| 4704 | + | |
| 4705 | + | |
4702 | 4706 | | |
4703 | 4707 | | |
4704 | 4708 | | |
4705 | 4709 | | |
4706 | | - | |
| 4710 | + | |
4707 | 4711 | | |
| 4712 | + | |
| 4713 | + | |
| 4714 | + | |
| 4715 | + | |
4708 | 4716 | | |
4709 | 4717 | | |
4710 | 4718 | | |
| |||
Lines changed: 16 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
895 | 895 | | |
896 | 896 | | |
897 | 897 | | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
898 | 906 | | |
899 | 907 | | |
900 | 908 | | |
| |||
1658 | 1666 | | |
1659 | 1667 | | |
1660 | 1668 | | |
| 1669 | + | |
| 1670 | + | |
| 1671 | + | |
| 1672 | + | |
| 1673 | + | |
| 1674 | + | |
| 1675 | + | |
| 1676 | + | |
1661 | 1677 | | |
1662 | 1678 | | |
1663 | 1679 | | |
| |||
Lines changed: 44 additions & 23 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
994 | 994 | | |
995 | 995 | | |
996 | 996 | | |
997 | | - | |
| 997 | + | |
998 | 998 | | |
999 | 999 | | |
1000 | 1000 | | |
| |||
1006 | 1006 | | |
1007 | 1007 | | |
1008 | 1008 | | |
1009 | | - | |
1010 | | - | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
1011 | 1012 | | |
1012 | | - | |
| 1013 | + | |
1013 | 1014 | | |
1014 | | - | |
1015 | | - | |
| 1015 | + | |
| 1016 | + | |
1016 | 1017 | | |
1017 | | - | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
1018 | 1023 | | |
1019 | | - | |
1020 | | - | |
1021 | | - | |
1022 | | - | |
1023 | | - | |
1024 | | - | |
1025 | | - | |
1026 | | - | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
1027 | 1036 | | |
1028 | | - | |
1029 | | - | |
1030 | 1037 | | |
1031 | | - | |
1032 | | - | |
1033 | | - | |
1034 | | - | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
1035 | 1045 | | |
1036 | | - | |
1037 | | - | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
1038 | 1059 | | |
1039 | 1060 | | |
1040 | 1061 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
508 | 508 | | |
509 | 509 | | |
510 | 510 | | |
| 511 | + | |
511 | 512 | | |
512 | 513 | | |
513 | 514 | | |
| |||
0 commit comments