Commit 71a28f3
authored
[ADT] Simplify DenseMapIterator with std::reverse_iterator (NFC) (llvm#157389)
DenseMapIterator has two tasks:
- iterate the buckets in the requested direction
- skip the empty and tombstone buckets
These tasks are intertwined in the current implementation.
This patch cleans up DenseMapIterator by separating the two tasks.
Specifically, we introduce a private middleman iterator type called
BucketItTy. This is the same as the pointer-based iterator in the
forward direction, but it becomes std::reverse_iterator<pointer>
otherwise. Now, the user-facing iterator iterates over BucketItTy
while skipping the empty and tombstone buckets. This way,
AdvancePastEmptyBuckets always calls BucketItTy::operator++. If the
reverse iteration is requested, the underlying raw pointer gets
decremented, but that logic is hidden behind
std::reverse_iterator<pointer>::operator++.
As a result, we can remove RetreatPastEmptyBuckets and a couple of
calls to shouldReverseIterate.
Here is a data point. A couple of months ago, we were calling
shouldReverseIterate from 18 places in DenseMap.h. That's down to 5.
This patch reduces it further down to 3.1 parent ee5bc57 commit 71a28f3
1 file changed
+23
-32
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1184 | 1184 | | |
1185 | 1185 | | |
1186 | 1186 | | |
1187 | | - | |
1188 | | - | |
| 1187 | + | |
| 1188 | + | |
| 1189 | + | |
1189 | 1190 | | |
1190 | | - | |
| 1191 | + | |
| 1192 | + | |
| 1193 | + | |
| 1194 | + | |
1191 | 1195 | | |
1192 | 1196 | | |
1193 | 1197 | | |
| |||
1201 | 1205 | | |
1202 | 1206 | | |
1203 | 1207 | | |
1204 | | - | |
1205 | | - | |
1206 | | - | |
1207 | | - | |
1208 | | - | |
1209 | | - | |
| 1208 | + | |
| 1209 | + | |
1210 | 1210 | | |
1211 | 1211 | | |
1212 | 1212 | | |
1213 | 1213 | | |
1214 | 1214 | | |
1215 | 1215 | | |
1216 | | - | |
1217 | | - | |
1218 | | - | |
| 1216 | + | |
| 1217 | + | |
1219 | 1218 | | |
1220 | 1219 | | |
1221 | 1220 | | |
1222 | 1221 | | |
1223 | 1222 | | |
1224 | | - | |
1225 | | - | |
1226 | | - | |
| 1223 | + | |
| 1224 | + | |
| 1225 | + | |
1227 | 1226 | | |
1228 | 1227 | | |
1229 | 1228 | | |
| |||
1238 | 1237 | | |
1239 | 1238 | | |
1240 | 1239 | | |
1241 | | - | |
1242 | | - | |
1243 | 1240 | | |
1244 | 1241 | | |
1245 | 1242 | | |
1246 | 1243 | | |
1247 | 1244 | | |
1248 | 1245 | | |
1249 | | - | |
1250 | | - | |
| 1246 | + | |
| 1247 | + | |
| 1248 | + | |
| 1249 | + | |
1251 | 1250 | | |
1252 | 1251 | | |
1253 | 1252 | | |
| |||
1261 | 1260 | | |
1262 | 1261 | | |
1263 | 1262 | | |
1264 | | - | |
1265 | | - | |
1266 | | - | |
1267 | | - | |
1268 | | - | |
1269 | 1263 | | |
1270 | 1264 | | |
1271 | 1265 | | |
| |||
1288 | 1282 | | |
1289 | 1283 | | |
1290 | 1284 | | |
1291 | | - | |
1292 | | - | |
1293 | | - | |
1294 | | - | |
1295 | | - | |
1296 | | - | |
1297 | | - | |
1298 | | - | |
| 1285 | + | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
1299 | 1290 | | |
1300 | 1291 | | |
1301 | 1292 | | |
| |||
0 commit comments