Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use or instead of || #371

Merged
merged 1 commit into from
Jul 2, 2024

Conversation

hauleth
Copy link
Member

@hauleth hauleth commented Jun 27, 2024

What kind of change does this PR introduce?

Replace uses of || with or in cases where both sides of operator are for
sure boolean.

Reason for that is that || works on other values than boolean, which mean that
a || b is translated to:

case a do
  val when val in [nil, false] -> b
  _ -> a
end

Which needs to perform more tests and cannot be optimised that easily by the
compiler. New code should be easier for compiler to optimise.

@hauleth hauleth force-pushed the chore/use-or-instead-of-pipes branch from b515458 to 91df94f Compare June 28, 2024 14:00
@hauleth hauleth changed the base branch from main to v2 June 28, 2024 14:06
@hauleth hauleth force-pushed the chore/use-or-instead-of-pipes branch 5 times, most recently from 563458a to 24f2bec Compare July 2, 2024 10:05
Reason for that is that `a || b` will expand to:

```
case a do
  val when val in [false, nil] -> b
  val -> val
end
```

Which is harder to optimise by the compiler. `or/2` works only with
booleans, so in places where we do not care about returned value or
`nil` cases, it is better to use `or/2`.
@hauleth hauleth force-pushed the chore/use-or-instead-of-pipes branch from 24f2bec to 2a59c0e Compare July 2, 2024 10:31
@hauleth hauleth marked this pull request as ready for review July 2, 2024 10:32
@hauleth hauleth requested a review from a team as a code owner July 2, 2024 10:32
@abc3 abc3 merged commit c1d9f9a into supabase:v2 Jul 2, 2024
5 checks passed
@hauleth hauleth deleted the chore/use-or-instead-of-pipes branch July 2, 2024 11:02
@hauleth hauleth mentioned this pull request Aug 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants