Skip to content

Cop idea: short-circuit logical expressions quickly by evaluating variables first #505

@vlad-pisanov

Description

@vlad-pisanov

Whenever there is a conditional branch with a logical disjunction or conjunction, reorder the terms so that all variables are evaluated first to hopefully short-circuit the expression and avoid any expensive method calls.

# bad
if costly_method? && local_var
  ...
end

# good
if local_var && costly_method?
  ...
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions