From 7d6d779377e63cd5ed78b8865b6ee4e3987a44ca Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Thu, 8 Sep 2022 16:20:14 -0700 Subject: [PATCH] [PersistentCollections] Convert global lets to computed properties This is just to prevent these from getting turned into global variables that are initialized on first access, especially once we make things inlinable. (I expect these will all get moved under some type eventually.) --- Sources/PersistentCollections/_Common.swift | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Sources/PersistentCollections/_Common.swift b/Sources/PersistentCollections/_Common.swift index 617bd171..436c3393 100644 --- a/Sources/PersistentCollections/_Common.swift +++ b/Sources/PersistentCollections/_Common.swift @@ -13,13 +13,19 @@ internal func _computeHash(_ value: T) -> Int { value.hashValue } -internal let _bitPartitionSize: Int = 5 +@inline(__always) +internal var _bitPartitionSize: Int { 5 } -internal let _bitPartitionMask: Int = (1 << _bitPartitionSize) - 1 +@inline(__always) +internal var _bitPartitionMask: Int { (1 << _bitPartitionSize) - 1 } -internal let _hashCodeLength: Int = Int.bitWidth +@inline(__always) +internal var _hashCodeLength: Int { Int.bitWidth } -internal let _maxDepth = (_hashCodeLength + _bitPartitionSize - 1) / _bitPartitionSize +@inline(__always) +internal var _maxDepth: Int { + (_hashCodeLength + _bitPartitionSize - 1) / _bitPartitionSize +} internal func _maskFrom(_ hash: Int, _ shift: Int) -> Int { (hash >> shift) & _bitPartitionMask