Skip to content

Commit 2bcfe9d

Browse files
committed
Little code clean
1 parent 64b202c commit 2bcfe9d

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

Sources/PerfectLib/Utilities.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ public struct UUID {
273273
u.deallocateCapacity(sizeof(uuid_t.self))
274274
}
275275
uuid_generate_random(u)
276-
self.uuid = uuid_t(u[0], u[1], u[2], u[3], u[4], u[5], u[6], u[7], u[8], u[9], u[10], u[11], u[12], u[13], u[14], u[15])
276+
self.uuid = UUID.uuidFromPointer(u)
277277
}
278278

279279
public init(_ string: String) {
@@ -282,27 +282,27 @@ public struct UUID {
282282
u.deallocateCapacity(sizeof(uuid_t.self))
283283
}
284284
uuid_parse(string, u)
285-
self.uuid = UUID.uuid_fromPointer(u)
286-
}
287-
288-
private static func uuid_fromPointer(_ u: UnsafeMutablePointer<UInt8>) -> uuid_t {
289-
// is there a better way?
290-
return uuid_t(u[0], u[1], u[2], u[3], u[4], u[5], u[6], u[7], u[8], u[9], u[10], u[11], u[12], u[13], u[14], u[15])
285+
self.uuid = UUID.uuidFromPointer(u)
291286
}
292287

293288
init(_ uuid: uuid_t) {
294289
self.uuid = uuid
295290
}
296291

292+
private static func uuidFromPointer(_ u: UnsafeMutablePointer<UInt8>) -> uuid_t {
293+
// is there a better way?
294+
return uuid_t(u[0], u[1], u[2], u[3], u[4], u[5], u[6], u[7], u[8], u[9], u[10], u[11], u[12], u[13], u[14], u[15])
295+
}
296+
297297
public var string: String {
298298
let u = UnsafeMutablePointer<UInt8>(allocatingCapacity: sizeof(uuid_t.self))
299299
let unu = UnsafeMutablePointer<Int8>(allocatingCapacity: 37) // as per spec. 36 + null
300300
defer {
301301
u.deallocateCapacity(sizeof(uuid_t.self))
302302
unu.deallocateCapacity(37)
303303
}
304-
u[0] = uuid.0;u[1] = uuid.1;u[2] = uuid.2;u[3] = uuid.3;u[4] = uuid.4;u[5] = uuid.5;u[6] = uuid.6;u[7] = uuid.7
305-
u[8] = uuid.8;u[9] = uuid.9;u[10] = uuid.10;u[11] = uuid.11;u[12] = uuid.12;u[13] = uuid.13;u[14] = uuid.14;u[15] = uuid.15
304+
var uu = self.uuid
305+
memcpy(u, &uu, sizeof(uuid_t.self))
306306
uuid_unparse_lower(u, unu)
307307
return String(validatingUTF8: unu)!
308308
}

0 commit comments

Comments
 (0)