Skip to content

Commit 9821976

Browse files
authored
Removes redundant buffer zeroing in CGColorSpace.swift by using `init(unsafeUninitializedCapacity:initializingWith:) (#30134)
* Removes redundant buffer zeroing * Fix compile error
1 parent 41958f9 commit 9821976

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

stdlib/public/Darwin/CoreGraphics/CoreGraphics.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,11 @@ extension CGColorSpace {
100100
public var colorTable: [UInt8]? {
101101
guard self.model == .indexed else { return nil }
102102
let components = self.baseColorSpace?.numberOfComponents ?? 1
103-
var table = [UInt8](repeating: 0, count: self.__colorTableCount * components)
104-
self.__unsafeGetColorTable(&table)
105-
return table
103+
let count = self.__colorTableCount * components
104+
return [UInt8](unsafeUninitializedCapacity: count) { buf, initializedCount in
105+
self.__unsafeGetColorTable(buf.baseAddress!)
106+
initializedCount = count
107+
}
106108
}
107109
}
108110

0 commit comments

Comments
 (0)