This is an archive of the discontinued LLVM Phabricator instance.

[libc++] Make common_iterator's proxy types into aggregates
ClosedPublic

Authored by Quuxplusone on Mar 7 2022, 8:48 AM.

Details

Summary

This is an alternative to one part of D120998; @ldionne, do you like this diff better than the corresponding diff in D120998?

This saves one move in each case, which is basically nothing perf-wise; this is more about simplifying the code.

Diff Detail

Event Timeline

Quuxplusone created this revision.Mar 7 2022, 8:48 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 7 2022, 8:48 AM
Quuxplusone requested review of this revision.Mar 7 2022, 8:48 AM
Herald added 1 blocking reviewer(s): Restricted Project. · View Herald TranscriptMar 7 2022, 8:48 AM
ldionne accepted this revision.Mar 7 2022, 9:25 AM

Yes, I like this better, if I understood the logic in my comment properly.

libcxx/include/__iterator/common_iterator.h
123

Right, so we know that _VSTD::__unchecked_get<_Iter>(__hold_) (aka the iterator) has a non-reference iter_reference_t, which is a complicated way of saying *iter is a temporary. So when we construct the aggregate now, we're even eliding a move operation. That sounds right?

This revision is now accepted and ready to land.Mar 7 2022, 9:25 AM
libcxx/include/__iterator/common_iterator.h
123

We're replacing a conversion iter_reference_t&& -> iter_value_t with a conversion iter_reference_t -> iter_value_t. In the case that iter_reference_t and iter_value_t are the same type, this is a savings. Otherwise, AIUI, it's really no different. (But I imagine that "they're the same type" is the common case.)

Also in the __postfix_proxy case, we're replacing iter_reference_t&& -> iter_reference_t with iter_reference_t -> iter_reference_t, which definitely saves one move-ctor of whatever type iter_reference_t is.