-
-
Notifications
You must be signed in to change notification settings - Fork 17.6k
impl Ord for bool: optimization #66780
Copy link
Copy link
Closed
Labels
C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.I-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.T-libs-api[DEPRECATED; DO NOT USE][DEPRECATED; DO NOT USE]
Description
Activity
Metadata
Metadata
Assignees
Labels
C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.I-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.T-libs-api[DEPRECATED; DO NOT USE][DEPRECATED; DO NOT USE]
Currently,
impl Ord for boolconverts thebools tou8s and then compares them.On the playground,
compiles to
A much shorter (in instruction count) and almost certainly faster version taking advantage of the fact that orderings are represented by
i8values -1, 0, and 1, is:which on the playground compiles to