Skip to content

Commit 1ff3345

Browse files
committed
Move variable into closure
1 parent 9a0f18b commit 1ff3345

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

stdlib/public/core/KeyPath.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,6 @@ public class KeyPath<Root, Value>: PartialKeyPath<Root> {
340340
}
341341
}
342342

343-
var currentType = rootType
344-
345343
return withBuffer {
346344
var buffer = $0
347345

@@ -380,6 +378,8 @@ public class KeyPath<Root, Value>: PartialKeyPath<Root> {
380378
$0.initializeElement(at: 0, to: root)
381379
}
382380

381+
var currentType = rootType
382+
383383
while true {
384384
let (rawComponent, optNextType) = buffer.next()
385385
let newType = optNextType ?? valueType

stdlib/public/core/TemporaryAllocation.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ internal func _isStackAllocationSafe(byteCount: Int, alignment: Int) -> Bool {
8484
// without worrying about running out of space, and the compiler would emit
8585
// such allocations on the stack anyway when they represent structures or
8686
// stack-promoted objects.
87-
if byteCount <= 1024 {
87+
if _fastPath(byteCount <= 1024) {
8888
return true
8989
}
9090

@@ -178,7 +178,8 @@ internal func _withUnprotectedUnsafeTemporaryAllocation<
178178
_ body: (Builtin.RawPointer) throws -> R
179179
) rethrows -> R {
180180
// How many bytes do we need to allocate?
181-
let byteCount = _byteCountForTemporaryAllocation(of: type, capacity: capacity)
181+
//let byteCount = _byteCountForTemporaryAllocation(of: type, capacity: capacity)
182+
let byteCount = MemoryLayout<T>.stride &* capacity
182183

183184
guard _isStackAllocationSafe(byteCount: byteCount, alignment: alignment) else {
184185
return try _fallBackToHeapAllocation(byteCount: byteCount, alignment: alignment, body)
@@ -294,7 +295,7 @@ public func _withUnprotectedUnsafeTemporaryAllocation<R: ~Copyable>(
294295
alignment: alignment
295296
) { pointer in
296297
let buffer = UnsafeMutableRawBufferPointer(
297-
start: .init(pointer),
298+
_uncheckedStart: .init(pointer),
298299
count: byteCount
299300
)
300301
return try body(buffer)
@@ -374,7 +375,7 @@ public func _withUnprotectedUnsafeTemporaryAllocation<
374375
) { pointer in
375376
Builtin.bindMemory(pointer, capacity._builtinWordValue, type)
376377
let buffer = UnsafeMutableBufferPointer<T>(
377-
start: .init(pointer),
378+
_uncheckedStart: .init(pointer),
378379
count: capacity
379380
)
380381
return try body(buffer)

stdlib/public/core/UnsafeRawBufferPointer.swift.gyb

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,21 @@ public struct Unsafe${Mutable}RawBufferPointer {
116116
_debugPrecondition(count >= 0, "${Self} with negative count")
117117
_debugPrecondition(count == 0 || start != nil,
118118
"${Self} has a nil start and nonzero count")
119+
120+
self.init(_uncheckedStart: start, count: count)
121+
}
122+
123+
@_alwaysEmitIntoClient
124+
internal init(
125+
_uncheckedStart start: Unsafe${Mutable}RawPointer?,
126+
count: Int
127+
) {
128+
_internalInvariant(count >= 0, "${Self} with negative count")
129+
_internalInvariant(
130+
count == 0 || start != nil,
131+
"${Self} has a nil start and nonzero count"
132+
)
133+
119134
_position = start
120135
_end = start.map { $0 + _assumeNonNegative(count) }
121136
}
@@ -1382,7 +1397,10 @@ public func _withUnprotectedUnsafeBytes<
13821397
#else
13831398
let addr = UnsafeRawPointer(Builtin.addressOfBorrow(value))
13841399
#endif
1385-
let buffer = UnsafeRawBufferPointer(start: addr, count: MemoryLayout<T>.size)
1400+
let buffer = UnsafeRawBufferPointer(
1401+
_uncheckedStart: addr,
1402+
count: MemoryLayout<T>.size
1403+
)
13861404
return try body(buffer)
13871405
}
13881406

0 commit comments

Comments
 (0)