Skip to content
This repository was archived by the owner on Dec 15, 2024. It is now read-only.

Commit 6e29f53

Browse files
committed
Updated for Swift 3.0
2016-07-23
1 parent d06e4ac commit 6e29f53

File tree

8 files changed

+21
-21
lines changed

8 files changed

+21
-21
lines changed

Sources/SwiftFoundation/Data.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100

101101
public var description: String {
102102

103-
let hexString = bytes.map({ $0.toHexadecimal() }).reduce("", combine: { $0.0 + $0.1 })
103+
let hexString = bytes.map({ $0.toHexadecimal() }).reduce("", { $0.0 + $0.1 })
104104

105105
return "<" + hexString + ">"
106106
}

Sources/SwiftFoundation/FileManager.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ public struct FileManager {
7575

7676
let stringBufferSize = Int(PATH_MAX)
7777

78-
let path = UnsafeMutablePointer<CChar>(allocatingCapacity: stringBufferSize)
78+
let path = UnsafeMutablePointer<CChar>.allocate(capacity: stringBufferSize)
7979

80-
defer { path.deallocateCapacity(stringBufferSize) }
80+
defer { path.deallocate(capacity: stringBufferSize) }
8181

8282
getcwd(path, stringBufferSize - 1)
8383

@@ -193,9 +193,9 @@ public struct FileManager {
193193

194194
#endif
195195

196-
let memoryPointer = UnsafeMutablePointer<Byte>(allocatingCapacity: fileSize)
196+
let memoryPointer = UnsafeMutablePointer<Byte>.allocate(capacity: fileSize)
197197

198-
defer { memoryPointer.deallocateCapacity(fileSize) }
198+
defer { memoryPointer.deallocate(capacity: fileSize) }
199199

200200
let readBytes = read(file, memoryPointer, fileSize)
201201

Sources/SwiftFoundation/Hash.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
public func Hash(_ data: Data) -> Int {
1111

1212
// more expensive than casting but that's not safe for large values.
13-
return data.bytes.map({ Int($0) }).reduce(0, combine: { $0.0 ^ $0.1 })
13+
return data.bytes.map({ Int($0) }).reduce(0, { $0.0 ^ $0.1 })
1414
}

Sources/SwiftFoundation/JSONParse.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ public extension JSON.Value {
1616

1717
public init?(string: Swift.String) {
1818

19-
let tokenerError: UnsafeMutablePointer<json_tokener_error>! = UnsafeMutablePointer<json_tokener_error>(allocatingCapacity: 1)
19+
let tokenerError: UnsafeMutablePointer<json_tokener_error>! = UnsafeMutablePointer<json_tokener_error>.allocate(capacity: 1)
2020

21-
defer { tokenerError.deallocateCapacity(1) }
21+
defer { tokenerError.deallocate(capacity: 1) }
2222

2323
let jsonObject = json_tokener_parse_verbose(string, tokenerError)
2424

Sources/SwiftFoundation/Lock.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
public final class Lock: Locking {
2424

25-
private var mutex = UnsafeMutablePointer<pthread_mutex_t>(allocatingCapacity: 1)
25+
private var mutex = UnsafeMutablePointer<pthread_mutex_t>.allocate(capacity: 1)
2626

2727
public init() {
2828
pthread_mutex_init(mutex, nil)
@@ -31,7 +31,7 @@
3131
deinit {
3232
pthread_mutex_destroy(mutex)
3333
mutex.deinitialize()
34-
mutex.deallocateCapacity(1)
34+
mutex.deallocate(capacity: 1)
3535
}
3636

3737
public func lock() {
@@ -131,7 +131,7 @@
131131
}
132132

133133
public final class RecursiveLock: Locking {
134-
private var mutex = UnsafeMutablePointer<pthread_mutex_t>(allocatingCapacity: 1)
134+
private var mutex = UnsafeMutablePointer<pthread_mutex_t>.allocate(capacity: 1)
135135

136136
public init() {
137137

@@ -145,7 +145,7 @@
145145
deinit {
146146
pthread_mutex_destroy(mutex)
147147
mutex.deinitialize()
148-
mutex.deallocateCapacity(1)
148+
mutex.deallocate(capacity: 1)
149149
}
150150

151151
public func lock() {
@@ -164,8 +164,8 @@
164164
}
165165

166166
public final class Condition: Locking {
167-
private var mutex = UnsafeMutablePointer<pthread_mutex_t>(allocatingCapacity: 1)
168-
private var cond = UnsafeMutablePointer<pthread_cond_t>(allocatingCapacity: 1)
167+
private var mutex = UnsafeMutablePointer<pthread_mutex_t>.allocate(capacity: 1)
168+
private var cond = UnsafeMutablePointer<pthread_cond_t>.allocate(capacity: 1)
169169

170170
public init() {
171171
pthread_mutex_init(mutex, nil)
@@ -177,8 +177,8 @@
177177
pthread_cond_destroy(cond)
178178
mutex.deinitialize()
179179
cond.deinitialize()
180-
mutex.deallocateCapacity(1)
181-
cond.deallocateCapacity(1)
180+
mutex.deallocate(capacity: 1)
181+
cond.deallocate(capacity: 1)
182182
}
183183

184184
public func lock() {

Sources/SwiftFoundation/POSIXRegularExpression.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public extension POSIXRegularExpression {
3939

4040
let numberOfMatches = re_nsub + 1 // first match is the expression itself, later matches are subexpressions
4141

42-
let matchesPointer = UnsafeMutablePointer<Match>.init(allocatingCapacity: numberOfMatches)
42+
let matchesPointer = UnsafeMutablePointer<Match>.allocate(capacity: numberOfMatches)
4343
defer { matchesPointer.deinitialize(count: numberOfMatches) }
4444

4545
let flags = options.optionsBitmask()

Sources/SwiftFoundation/UUID.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@
5959

6060
init?(rawValue: String) {
6161

62-
let uuidPointer = UnsafeMutablePointer<uuid_t>(allocatingCapacity: 1)
62+
let uuidPointer = UnsafeMutablePointer<uuid_t>.allocate(capacity: 1)
6363

64-
defer { uuidPointer.deallocateCapacity(1) }
64+
defer { uuidPointer.deallocate(capacity: 1) }
6565

6666
guard uuid_parse(rawValue, unsafeBitCast(uuidPointer, to: UnsafeMutablePointer<UInt8>.self)) != -1
6767
else { return nil }

Sources/UnitTests/DataTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ final class DataTests: XCTestCase {
2525

2626
XCTAssert(testData.isEmpty == false, "Could not create test data")
2727

28-
let dataPointer = UnsafeMutablePointer<Byte>(allocatingCapacity: testData.count)
28+
let dataPointer = UnsafeMutablePointer<Byte>.allocate(capacity: testData.count)
2929

30-
defer { dataPointer.deallocateCapacity(testData.count) }
30+
defer { dataPointer.deallocate(capacity: testData.count) }
3131

3232
memcpy(dataPointer, testData.bytes, testData.count)
3333

0 commit comments

Comments
 (0)