Commit 4d91323
authored
Auto merge of #36355 - bluss:vec-extend-from-slice-aliasing-workaround, r=alexcrichton
Work around pointer aliasing issue in Vec::extend_from_slice, extend_with_element
Due to missing noalias annotations for &mut T in general (issue #31681),
in larger programs extend_from_slice and extend_with_element may both
compile very poorly. What is observed is that the .set_len() calls are
not lifted out of the loop, even for `Vec<u8>`.
Use a local length variable for the Vec length instead, and use a scope
guard to write this value back to self.len when the scope ends or on
panic. Then the alias analysis is easy.
This affects extend_from_slice, extend_with_element, the vec![x; n]
macro, Write impls for Vec<u8>, BufWriter, etc (but may / may not
have triggered since inlining can be enough for the compiler to get it right).
Fixes #32155
Fixes #33518
Closes #178441 file changed
+55
-13
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1046 | 1046 | | |
1047 | 1047 | | |
1048 | 1048 | | |
1049 | | - | |
1050 | | - | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
1051 | 1055 | | |
1052 | | - | |
| 1056 | + | |
1053 | 1057 | | |
1054 | 1058 | | |
1055 | 1059 | | |
1056 | | - | |
| 1060 | + | |
1057 | 1061 | | |
1058 | 1062 | | |
1059 | 1063 | | |
1060 | 1064 | | |
1061 | 1065 | | |
1062 | | - | |
| 1066 | + | |
1063 | 1067 | | |
| 1068 | + | |
| 1069 | + | |
1064 | 1070 | | |
1065 | 1071 | | |
1066 | 1072 | | |
| |||
1085 | 1091 | | |
1086 | 1092 | | |
1087 | 1093 | | |
1088 | | - | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
1089 | 1098 | | |
1090 | | - | |
1091 | | - | |
1092 | | - | |
1093 | | - | |
1094 | | - | |
1095 | | - | |
1096 | | - | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
1097 | 1108 | | |
| 1109 | + | |
| 1110 | + | |
1098 | 1111 | | |
1099 | 1112 | | |
1100 | 1113 | | |
1101 | 1114 | | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
| 1120 | + | |
| 1121 | + | |
| 1122 | + | |
| 1123 | + | |
| 1124 | + | |
| 1125 | + | |
| 1126 | + | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
| 1130 | + | |
| 1131 | + | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
1102 | 1144 | | |
1103 | 1145 | | |
1104 | 1146 | | |
| |||
0 commit comments