Skip to content

Commit

Permalink
Merge pull request #330 from jpsim/jp-remove-uid-cache
Browse files Browse the repository at this point in the history
remove UID map and lock
  • Loading branch information
jpsim authored Jan 10, 2017
2 parents b325ca1 + 9ebe120 commit 380a5f6
Showing 1 changed file with 1 addition and 26 deletions.
27 changes: 1 addition & 26 deletions Source/SourceKittenFramework/Request.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,36 +117,13 @@ private let initializeSourceKitFailable: Void = {
/// dispatch_semaphore_t used when waiting for sourcekitd to be restored.
private var sourceKitWaitingRestoredSemaphore = DispatchSemaphore(value: 0)

/// SourceKit UID to String map.
private var _uidStringMap = [sourcekitd_uid_t: String]()
private var _uidStringMapLock = NSLock()

/// Thread safe read from sourceKitUID map
private func uidString(`for` sourceKitUID: sourcekitd_uid_t) -> String? {
_uidStringMapLock.lock()
defer { _uidStringMapLock.unlock() }
return _uidStringMap[sourceKitUID]
}

/// Thread safe write from sourceKitUID map
private func setUIDString(uidString: String, `for` identifier: sourcekitd_uid_t) {
_uidStringMapLock.lock()
defer { _uidStringMapLock.unlock() }
_uidStringMap[identifier] = uidString
}

private extension String {
/**
Cache SourceKit requests for strings from UIDs

- returns: Cached UID string if available, nil otherwise.
*/
init?(sourceKitUID: sourcekitd_uid_t) {
if let string = uidString(for: sourceKitUID) {
self = string
return
}

let length = sourcekitd_uid_get_length(sourceKitUID)
let bytes = sourcekitd_uid_get_string_ptr(sourceKitUID)
if let uidString = String(bytes: bytes!, length: length) {
Expand All @@ -161,10 +138,8 @@ private extension String {
For avoiding those penalty, replaces with enum's rawValue String if defined in SourceKitten.
That does not cause calling `decomposedStringWithCanonicalMapping`.
*/
let uidString = String(uidString: uidString)
setUIDString(uidString: uidString, for: sourceKitUID)

self = uidString
self = String(uidString: uidString)
return
}
return nil
Expand Down

0 comments on commit 380a5f6

Please sign in to comment.