| Code-Review | +1 |
lgtm, constructing with the right size is the cheapest primitive for the GC
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Code-Review | +1 |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Use the Vector/HeapVector projection constructor.
Vector and HeapVector have grown a new constructor that take in a
range and a projection (a lambda), effectively creating the vector
in one go. (Actually HeapVector's was limited to other HeapVectors,
but we extend it to the same Range lambda as Vector.) This replaces
our previous pattern of ReserveInitialCapacity and repeated
push_back (or AppendUnchecked):
- It is safer, as there is no way to reserve a different number of
elements from the number you AppendUnchecked, and because it
naturally lends itself to spanification of the input data.
- It generates less code, since HeapVector does not need barriers
in this case (the constructed object is guaranteed to never
leave the stack while we are pushing the elements). It also does
not need any bounds-checking.
- It is also possibly marginally faster, again due to the above.
However, the effect is very slight; on Speedometer3, it is either
neutral or very weakly positive.
The aesthetics are debatable, but overall it seems mostly fine to me,
so we use it for all relevant CSS loops that I could find, by grepping
for ReserveInitialCapacity. (The primary missing cases are the ones
where we need a filter, so that we don't actually end up pushing
as many elements as we assume we will.)
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |