This is an archive of the discontinued LLVM Phabricator instance.

[ADT] Avoid needless iterator copies in `zippy`
ClosedPublic

Authored by kuhar on Mar 5 2023, 3:51 PM.

Details

Summary

Make zip_common increment and decrement iterators in place.

This improves performance with iterator types that have non-triviall
copy constructors.

Diff Detail

Event Timeline

kuhar created this revision.Mar 5 2023, 3:51 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 5 2023, 3:51 PM
Herald added a subscriber: hanchung. · View Herald Transcript
kuhar requested review of this revision.Mar 5 2023, 3:51 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 5 2023, 3:51 PM
zero9178 added inline comments.Mar 6 2023, 9:14 AM
llvm/include/llvm/ADT/STLExtras.h
789

ultra nit: We only usually use explicit casts to void for silencing unused variable warning don't we? Looks a bit odd here imo

llvm/unittests/ADT/IteratorTest.cpp
731

How fragile is this test? Isn't the initial copy count more or less an implementation detail of zippy? Would it maybe suffice to create the zippy range before the loop, record the count, then do the loop, and then ensure that the count after the loop is equal to before?

kuhar updated this revision to Diff 502714.Mar 6 2023, 10:39 AM

Address comments. Rebase.

kuhar marked 2 inline comments as done.Mar 6 2023, 10:42 AM
kuhar added inline comments.
llvm/include/llvm/ADT/STLExtras.h
789

I added (void) to avoid potential warnings about unused return values, but thinking about it again, it's probably signal that shouldn't be ignored in the first place. Thanks!

llvm/unittests/ADT/IteratorTest.cpp
731

The number of copies in the loop is still >0 (4 to be exact), but I followed your suggestion and separated the pre-loop count from the in-loop count.

zero9178 accepted this revision.Mar 6 2023, 11:33 AM

LGTM thanks!

llvm/unittests/ADT/IteratorTest.cpp
731

Ahh I see, these seem to come from the begin and end calls that the for-range loop desugars to. One could probably separate the counting of those too, but I think the current method is fine.

This revision is now accepted and ready to land.Mar 6 2023, 11:33 AM
This revision was landed with ongoing or failed builds.Mar 6 2023, 11:45 AM
This revision was automatically updated to reflect the committed changes.