File tree Expand file tree Collapse file tree 1 file changed +7
-11
lines changed Expand file tree Collapse file tree 1 file changed +7
-11
lines changed Original file line number Diff line number Diff line change @@ -162,27 +162,23 @@ public class AnyKeyPath: Hashable, _AppendKeyPath {
162
162
163
163
func getOffsetFromStorage( ) -> Int ? {
164
164
let maximumOffsetOn32BitArchitecture = 4094
165
- guard let storage = _kvcKeyPathStringPtr else {
165
+ guard _kvcKeyPathStringPtr != nil else {
166
166
return nil
167
167
}
168
168
169
- // TODO: Maybe we can get a pointer's raw bits instead of doing
170
- // a distance calculation. Note: offsetBase can't be unwrapped
171
- // forcefully if its bitPattern is 0x00. Hence the 0x01.
172
- let offsetBase = UnsafePointer < CChar > ( bitPattern: 0x01 )
173
169
let architectureSize = MemoryLayout< Int> . size
174
170
if architectureSize == 8 {
175
- let storageDistance = storage . distance ( to : offsetBase! ) - 2
176
- guard storageDistance >= 0 else {
171
+ let offset = - Int ( bitPattern : _kvcKeyPathStringPtr ) - 1
172
+ guard offset >= 0 else {
177
173
// This happens to be an actual _kvcKeyPathStringPtr, not an offset, if we get here.
178
174
return nil
179
175
}
180
- return storageDistance
176
+ return offset
181
177
}
182
178
else {
183
- let storageDistance = offsetBase! . distance ( to : storage )
184
- if ( storageDistance <= maximumOffsetOn32BitArchitecture) {
185
- return storageDistance
179
+ let offset = Int ( bitPattern : _kvcKeyPathStringPtr ) - 1
180
+ if ( offset <= maximumOffsetOn32BitArchitecture) {
181
+ return offset
186
182
}
187
183
return nil
188
184
}
You can’t perform that action at this time.
0 commit comments