Skip to content

Most common patterns could be evaluated first and once to reduce code size #29033

@alrz

Description

@alrz

Version Used: features/recursive-patterns

Steps to Reproduce:

These two methods produce the same result but since the second one is already sorted by most common patterns, it generates significantly better code.

    public static bool M1(int i, int j, int k) {
        switch(i, j, k) {
            case (0, 1, 3):
            case (1, 1, 3):
                return true;
            default:
                return false;
        }
    }

    public static bool M2(int i, int j, int k) {
        switch(k, j, i) {
            case (3, 1, 0):
            case (3, 1, 1):
                return true;
            default:
                return false;
        }
    }

Expected Behavior:

The generated code should match the most common patterns first, no matter what order they appear in the source.

Actual Behavior:

The generated code reflects the order in which patterns are appeared in the source.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions