NetNewsWire/Frameworks/Articles/DatabaseID.swift

33 lines
694 B
Swift
Raw Normal View History

//
// DatabaseID.swift
// NetNewsWire
//
// Created by Brent Simmons on 7/15/17.
// Copyright © 2017 Ranchero Software. All rights reserved.
//
import Foundation
import RSCore
// MD5 works because:
// * Its fast
// * Collisions arent going to happen with feed data
private var databaseIDCache = [String: String]()
2017-09-11 15:46:32 +02:00
private var databaseIDCacheLock = os_unfair_lock_s()
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)
}
if let identifier = databaseIDCache[s] {
return identifier
}
2020-01-18 08:00:56 +01:00
let identifier = s.md5String
databaseIDCache[s] = identifier
return identifier
}