Skip to content

Commit

Permalink
Improve performance by making parameter rhs of optional logical ope…
Browse files Browse the repository at this point in the history
…rators `Bool` a autoclosure
  • Loading branch information
F1248 committed Jan 6, 2025
1 parent dc18771 commit 836d04b
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions Genius/Extensions/Swift/Bool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,19 @@ extension Bool? {
bool.map(!)
}

static func &&? (lhs: Self, rhs: Self) -> Self {
if let lhs, let rhs {
lhs && rhs
} else if [lhs, rhs].contains(false) {
false
} else { nil }
static func &&? (lhs: Self, rhs: @autoclosure () -> Self) -> Self {
switch lhs {
case true: rhs()
case false: false
default: rhs() == false ? false : nil
}
}

static func ||? (lhs: Self, rhs: Self) -> Self {
if let lhs, let rhs {
lhs || rhs
} else if [lhs, rhs].contains(true) {
true
} else { nil }
static func ||? (lhs: Self, rhs: @autoclosure () -> Self) -> Self {
switch lhs {
case true: true
case false: rhs()
default: rhs() == true ? true : nil
}
}
}

0 comments on commit 836d04b

Please sign in to comment.