Skip to content

Commit 58ad356

Browse files
author
Mayank
committed
Refactored the Stack.swift file to make it more readable.
Instead of using `if` in case of checking if `index < end` in `next` function of Stack. We can use `guard` statement to make it more readable and concise.
1 parent 8f0382c commit 58ad356

File tree

1 file changed

+10
-10
lines changed
  • SwiftCompilerSources/Sources/Optimizer/DataStructures

1 file changed

+10
-10
lines changed

SwiftCompilerSources/Sources/Optimizer/DataStructures/Stack.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,17 @@ struct Stack<Element> : CollectionLikeSequence {
4747

4848
mutating func next() -> Element? {
4949
let end = (slab.data == lastSlab.data ? endIndex : slabCapacity)
50-
if index < end {
51-
let elem = Stack.bind(slab)[index]
52-
index += 1
53-
54-
if index >= end && slab.data != lastSlab.data {
55-
slab = slab.getNext()
56-
index = 0
57-
}
58-
return elem
50+
51+
guard index < end else { return nil }
52+
53+
let elem = Stack.bind(slab)[index]
54+
index += 1
55+
56+
if index >= end && slab.data != lastSlab.data {
57+
slab = slab.getNext()
58+
index = 0
5959
}
60-
return nil
60+
return elem
6161
}
6262
}
6363

0 commit comments

Comments
 (0)