Skip to content

Commit 072dca3

Browse files
pookjwKyle-Ye
authored andcommitted
[NFC] Optimize AlignmentKey.bits calculation logic
1 parent 0d222b7 commit 072dca3

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

Sources/OpenSwiftUICore/Layout/Alignment/AlignmentGuide.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,13 +1235,16 @@ public struct AlignmentKey: Hashable, Comparable {
12351235
private let bits: UInt
12361236

12371237
package var id: any AlignmentID.Type {
1238-
Self.typeCache.types[index]
1238+
let cache = Self.typeCache
1239+
return cache.types[index]
12391240
}
12401241

12411242
package var axis: Axis { bits & 1 == 0 ? .horizontal : .vertical }
12421243

12431244
@inline(__always)
1244-
var index: Int { Int(bits / 2 - 1) }
1245+
var index: Int {
1246+
Int(bitPattern: (bits - 2) >> 1)
1247+
}
12451248

12461249
package init(id: any AlignmentID.Type, axis: Axis) {
12471250
let index = Self.$typeCache.access { cache in
@@ -1255,7 +1258,7 @@ public struct AlignmentKey: Hashable, Comparable {
12551258
return index
12561259
}
12571260
}
1258-
bits = (axis == .horizontal ? 0 : 1) + (index + 1) * 2
1261+
bits = (index << 1 &+ 2) | (axis == .horizontal ? 0 : 1)
12591262
}
12601263

12611264
package init() { bits = .zero }

0 commit comments

Comments
 (0)