2017-07-17 04:36:38 +02:00
|
|
|
|
//
|
|
|
|
|
// DatabaseID.swift
|
2019-07-09 07:58:19 +02:00
|
|
|
|
// NetNewsWire
|
2017-07-17 04:36:38 +02:00
|
|
|
|
//
|
|
|
|
|
// Created by Brent Simmons on 7/15/17.
|
|
|
|
|
// Copyright © 2017 Ranchero Software. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import Foundation
|
2017-09-03 01:08:02 +02:00
|
|
|
|
import RSCore
|
2017-07-17 04:36:38 +02:00
|
|
|
|
|
|
|
|
|
// MD5 works because:
|
|
|
|
|
// * It’s fast
|
|
|
|
|
// * Collisions aren’t going to happen with feed data
|
|
|
|
|
|
2017-09-02 23:19:42 +02:00
|
|
|
|
private var databaseIDCache = [String: String]()
|
2017-09-11 15:46:32 +02:00
|
|
|
|
private var databaseIDCacheLock = os_unfair_lock_s()
|
2017-09-02 23:19:42 +02:00
|
|
|
|
|
2017-09-19 07:00:35 +02:00
|
|
|
|
public func databaseIDWithString(_ s: String) -> String {
|
2017-09-11 15:46:32 +02:00
|
|
|
|
os_unfair_lock_lock(&databaseIDCacheLock)
|
|
|
|
|
defer {
|
|
|
|
|
os_unfair_lock_unlock(&databaseIDCacheLock)
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-02 23:19:42 +02:00
|
|
|
|
if let identifier = databaseIDCache[s] {
|
|
|
|
|
return identifier
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-18 08:00:56 +01:00
|
|
|
|
let identifier = s.md5String
|
2017-09-02 23:19:42 +02:00
|
|
|
|
databaseIDCache[s] = identifier
|
|
|
|
|
return identifier
|
2017-07-17 04:36:38 +02:00
|
|
|
|
}
|