This is an archive of the discontinued LLVM Phabricator instance.

[libc++][NFC] Simplify __sort{4,5}
ClosedPublic

Authored by philnik on Feb 21 2023, 6:09 AM.

Details

Summary

Don't return the number of swaps; it's not used anywhere.

Diff Detail

Event Timeline

philnik created this revision.Feb 21 2023, 6:09 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 21 2023, 6:09 AM
philnik requested review of this revision.Feb 21 2023, 6:09 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 21 2023, 6:09 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript
avogelsgesang accepted this revision.Feb 21 2023, 6:14 AM
avogelsgesang added a subscriber: avogelsgesang.

LGTM

philnik updated this revision to Diff 499143.Feb 21 2023, 6:14 AM
philnik removed a subscriber: avogelsgesang.

__sort3 is used in nth_element, where the swap count is actually used, so that can't be simplified

philnik retitled this revision from [libc++][NFC] Simplify __sort{3,4,5} to [libc++][NFC] Simplify __sort{4,5}.Feb 21 2023, 6:14 AM
Mordante accepted this revision.Feb 21 2023, 9:07 AM

Nice catch! LGTM!

Did you happen to benchmark the performance difference?

libcxx/include/__algorithm/sort.h
49

I would be tempted to return a bool instead, it seems __nth_element only cares about whether or not a swap is done. (Obviously something for a separate patch.)

This revision is now accepted and ready to land.Feb 21 2023, 9:07 AM
This revision was automatically updated to reflect the committed changes.