Skip to content

Commit f9773c3

Browse files
committed
Move variable into closure
1 parent c1c6bd7 commit f9773c3

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
@@ -342,8 +342,6 @@ public class KeyPath<Root, Value>: PartialKeyPath<Root> {
342342
}
343343
}
344344

345-
var currentType = rootType
346-
347345
return withBuffer {
348346
var buffer = $0
349347

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

383+
var currentType = rootType
384+
385385
while true {
386386
let (rawComponent, optNextType) = buffer.next()
387387
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)
@@ -302,7 +303,7 @@ public func _withUnprotectedUnsafeTemporaryAllocation<R: ~Copyable>(
302303
alignment: alignment
303304
) { pointer in
304305
let buffer = UnsafeMutableRawBufferPointer(
305-
start: .init(pointer),
306+
_uncheckedStart: .init(pointer),
306307
count: byteCount
307308
)
308309
return try body(buffer)
@@ -382,7 +383,7 @@ public func _withUnprotectedUnsafeTemporaryAllocation<
382383
) { pointer in
383384
Builtin.bindMemory(pointer, capacity._builtinWordValue, type)
384385
let buffer = UnsafeMutableBufferPointer<T>(
385-
start: .init(pointer),
386+
_uncheckedStart: .init(pointer),
386387
count: capacity
387388
)
388389
return try body(buffer)

stdlib/public/core/UnsafeRawBufferPointer.swift.gyb

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,21 @@ public struct Unsafe${Mutable}RawBufferPointer {
115115
_debugPrecondition(count >= 0, "${Self} with negative count")
116116
_debugPrecondition(count == 0 || start != nil,
117117
"${Self} has a nil start and nonzero count")
118+
119+
self.init(_uncheckedStart: start, count: count)
120+
}
121+
122+
@_alwaysEmitIntoClient
123+
internal init(
124+
_uncheckedStart start: Unsafe${Mutable}RawPointer?,
125+
count: Int
126+
) {
127+
_internalInvariant(count >= 0, "${Self} with negative count")
128+
_internalInvariant(
129+
count == 0 || start != nil,
130+
"${Self} has a nil start and nonzero count"
131+
)
132+
118133
_position = start
119134
_end = start.map { $0 + _assumeNonNegative(count) }
120135
}
@@ -1393,7 +1408,10 @@ public func _withUnprotectedUnsafeBytes<
13931408
#else
13941409
let addr = UnsafeRawPointer(Builtin.addressOfBorrow(value))
13951410
#endif
1396-
let buffer = UnsafeRawBufferPointer(start: addr, count: MemoryLayout<T>.size)
1411+
let buffer = UnsafeRawBufferPointer(
1412+
_uncheckedStart: addr,
1413+
count: MemoryLayout<T>.size
1414+
)
13971415
return try body(buffer)
13981416
}
13991417

0 commit comments

Comments
 (0)