Skip to content

Optimize conditions with numeric literal (while (1)) #241

Description

@laurenthuberdeau

For loops and conditions, when a non-zero literal appears as the condition (such as while(1)), we can generate while :; ... instead of while [ 1 != 0 ]; ... to avoid unnecessary comparisons. Similarly, loops and conditions that never execute or execute only once (do { ... } while (0)) could be removed.

The resulting code may be slightly faster on some shells, but it may not be worth the effort and increased code size.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions