@@ -2903,11 +2903,19 @@ internal struct _Native${Self}Buffer<${TypeParameters}> {
2903
2903
bitCount: capacity)
2904
2904
initializedEntries.initializeToZero()
2905
2905
2906
+ // Compute all the array offsets now, so we don't have to later
2907
+ let bitmapAddr = Builtin.projectTailElems(_storage, UInt.self)
2908
+ let numWordsForBitmap = _UnsafeBitMap.sizeInWords(forSizeInBits: capacity)
2909
+ let keysAddr = Builtin.getTailAddr_Word(bitmapAddr,
2910
+ numWordsForBitmap._builtinWordValue, UInt.self, Key.self)
2911
+
2906
2912
// Initialize header
2907
2913
_body.initializedEntries = initializedEntries
2908
- _body.keys = UnsafeMutableRawPointer(_keys )
2914
+ _body.keys = UnsafeMutableRawPointer(keysAddr )
2909
2915
%if Self == 'Dictionary':
2910
- _body.values = UnsafeMutableRawPointer(_values)
2916
+ let valuesAddr = Builtin.getTailAddr_Word(keysAddr,
2917
+ capacity._builtinWordValue, Key.self, Value.self)
2918
+ _body.values = UnsafeMutableRawPointer(valuesAddr)
2911
2919
%end
2912
2920
}
2913
2921
@@ -2947,27 +2955,15 @@ internal struct _Native${Self}Buffer<${TypeParameters}> {
2947
2955
return _storage._initializedHashtableEntriesBitMapBuffer
2948
2956
}
2949
2957
2950
- // This is just a convenience for computing the offset of the keys array to
2951
- // avoid _keys and _values duplicating logic.
2952
- internal var _keysRawAddr: Builtin.RawPointer {
2953
- // Gets the offset for the bitmap, then derives the key offset from that.
2954
- let bitmapAddr = Builtin.projectTailElems(_storage, UInt.self)
2955
- let numWordsForBitmap = _UnsafeBitMap.sizeInWords(forSizeInBits: capacity)
2956
- return Builtin.getTailAddr_Word(bitmapAddr,
2957
- numWordsForBitmap._builtinWordValue, UInt.self, Key.self)
2958
- }
2959
-
2960
2958
// This API is unsafe and needs a `_fixLifetime` in the caller.
2961
- internal var _keys : UnsafeMutablePointer<Key> {
2962
- return UnsafeMutablePointer(_keysRawAddr )
2959
+ internal var keys : UnsafeMutablePointer<Key> {
2960
+ return _body.keys.assumingMemoryBound(to: Key.self )
2963
2961
}
2964
2962
2965
2963
%if Self == 'Dictionary':
2966
2964
// This API is unsafe and needs a `_fixLifetime` in the caller.
2967
- internal var _values: UnsafeMutablePointer<Value> {
2968
- let valuesAddr = Builtin.getTailAddr_Word(_keysRawAddr,
2969
- capacity._builtinWordValue, Key.self, Value.self)
2970
- return UnsafeMutablePointer(valuesAddr)
2965
+ internal var values: UnsafeMutablePointer<Value> {
2966
+ return _body.values.assumingMemoryBound(to: Value.self)
2971
2967
}
2972
2968
%end
2973
2969
@@ -2993,7 +2989,7 @@ internal struct _Native${Self}Buffer<${TypeParameters}> {
2993
2989
_sanityCheck(isInitializedEntry(at: i))
2994
2990
defer { _fixLifetime(self) }
2995
2991
2996
- let res = (_keys + i).pointee
2992
+ let res = (keys + i).pointee
2997
2993
return res
2998
2994
}
2999
2995
@@ -3028,9 +3024,9 @@ internal struct _Native${Self}Buffer<${TypeParameters}> {
3028
3024
_sanityCheck(isInitializedEntry(at: i))
3029
3025
defer { _fixLifetime(self) }
3030
3026
3031
- (_keys + i).deinitialize()
3027
+ (keys + i).deinitialize()
3032
3028
%if Self == 'Dictionary':
3033
- (_values + i).deinitialize()
3029
+ (values + i).deinitialize()
3034
3030
%end
3035
3031
_body.initializedEntries[i] = false
3036
3032
}
@@ -3041,7 +3037,7 @@ internal struct _Native${Self}Buffer<${TypeParameters}> {
3041
3037
_sanityCheck(!isInitializedEntry(at: i))
3042
3038
defer { _fixLifetime(self) }
3043
3039
3044
- (_keys + i).initialize(to: k)
3040
+ (keys + i).initialize(to: k)
3045
3041
_body.initializedEntries[i] = true
3046
3042
}
3047
3043
@@ -3051,7 +3047,7 @@ internal struct _Native${Self}Buffer<${TypeParameters}> {
3051
3047
3052
3048
defer { _fixLifetime(self) }
3053
3049
3054
- (_keys + toEntryAt).initialize(to: (from._keys + at).move())
3050
+ (keys + toEntryAt).initialize(to: (from.keys + at).move())
3055
3051
from._body.initializedEntries[at] = false
3056
3052
_body.initializedEntries[toEntryAt] = true
3057
3053
}
@@ -3068,7 +3064,7 @@ internal struct _Native${Self}Buffer<${TypeParameters}> {
3068
3064
_sanityCheck(isInitializedEntry(at: i))
3069
3065
defer { _fixLifetime(self) }
3070
3066
3071
- (_keys + i).pointee = key
3067
+ (keys + i).pointee = key
3072
3068
}
3073
3069
3074
3070
%elif Self == 'Dictionary':
@@ -3077,8 +3073,8 @@ internal struct _Native${Self}Buffer<${TypeParameters}> {
3077
3073
_sanityCheck(!isInitializedEntry(at: i))
3078
3074
defer { _fixLifetime(self) }
3079
3075
3080
- (_keys + i).initialize(to: k)
3081
- (_values + i).initialize(to: v)
3076
+ (keys + i).initialize(to: k)
3077
+ (values + i).initialize(to: v)
3082
3078
_body.initializedEntries[i] = true
3083
3079
}
3084
3080
@@ -3087,8 +3083,8 @@ internal struct _Native${Self}Buffer<${TypeParameters}> {
3087
3083
_sanityCheck(!isInitializedEntry(at: toEntryAt))
3088
3084
defer { _fixLifetime(self) }
3089
3085
3090
- (_keys + toEntryAt).initialize(to: (from._keys + at).move())
3091
- (_values + toEntryAt).initialize(to: (from._values + at).move())
3086
+ (keys + toEntryAt).initialize(to: (from.keys + at).move())
3087
+ (values + toEntryAt).initialize(to: (from.values + at).move())
3092
3088
from._body.initializedEntries[at] = false
3093
3089
_body.initializedEntries[toEntryAt] = true
3094
3090
}
@@ -3099,16 +3095,16 @@ internal struct _Native${Self}Buffer<${TypeParameters}> {
3099
3095
_sanityCheck(isInitializedEntry(at: i))
3100
3096
defer { _fixLifetime(self) }
3101
3097
3102
- return (_values + i).pointee
3098
+ return (values + i).pointee
3103
3099
}
3104
3100
3105
3101
@_transparent
3106
3102
internal func setKey(_ key: Key, value: Value, at i: Int) {
3107
3103
_sanityCheck(isInitializedEntry(at: i))
3108
3104
defer { _fixLifetime(self) }
3109
3105
3110
- (_keys + i).pointee = key
3111
- (_values + i).pointee = value
3106
+ (keys + i).pointee = key
3107
+ (values + i).pointee = value
3112
3108
}
3113
3109
3114
3110
%end
0 commit comments