on 68a32d7 help sign in
Sources/App/Models/SafeDict.swift+3−11
since splitsnapshots
unifiedsplit
@@ -7,14 +7,6 @@
7
7
8import Foundation
8import Foundation
9
9
10−func getRandomNum(_ min: Int, _ max: Int) -> Int {
11− #if os(Linux)
12− return Int(random() % max) + min
13− #else
14− return Int(arc4random_uniform(UInt32(max)) + UInt32(min))
15− #endif
16−}
17−
18struct SafeDict<Key: Hashable, Value> {
10struct SafeDict<Key: Hashable, Value> {
19 private var queue = DispatchQueue(label: "soy.iko.safeDict.queue", attributes: .concurrent)
11 private var queue = DispatchQueue(label: "soy.iko.safeDict.queue", attributes: .concurrent)
20
12
@@ -41,9 +33,9 @@ struct SafeDict<Key: Hashable, Value> {
41 mutating func removeRandom() -> Key? {
33 mutating func removeRandom() -> Key? {
42 var key: Key?
34 var key: Key?
43 queue.sync(flags: .barrier) {
35 queue.sync(flags: .barrier) {
44− if dict.count > 0 {
36+ key = dict.keys.randomElement()
45− key = Array(dict.keys)[getRandomNum(0, dict.count)]
37+ if let key = key {
46− dict[key!] = nil
38+ dict[key] = nil
47 }
39 }
48 }
40 }
49 return key
41 return key
Sources/App/routes.swift−4
@@ -33,10 +33,6 @@ public func routes(_ router: Router) throws {
33 }
33 }
34 return post
34 return post
35 }
35 }
36−
37− router.get("posts") { (req) -> [Post] in
38− return Array(Post.storage.values)
39− }
40}
36}
41
37
42enum DatabaseError: Error, AbortError {
38enum DatabaseError: Error, AbortError {
Sources/Run/main.swift−6
@@ -1,9 +1,3 @@
1import App
1import App
2
2
3−#if os(Linux)
4−import SwiftGlibc
5−srandom(UInt32(time(nil)))
6−#endif
7−
8−
9try app(.detect()).run()
3try app(.detect()).run()