Skip to content

Commit 1999d33

Browse files
authored
Merge pull request #248 from p-x9/feature/retain-symbol-cache
2 parents 19b4cfe + 9e9a8af commit 1999d33

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

Sources/MachOKit/DyldCache.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ public class DyldCache: DyldCacheRepresentable, _DyldCacheFileRepresentable {
3737
internal var _fullCache: FullDyldCache?
3838
// Retain the main cache
3939
private var _mainCache: DyldCache?
40+
// Retain the symbol cache
41+
internal var _symbolCache: DyldCache?
4042

4143
public var headerSize: Int {
4244
header.actualSize
@@ -235,16 +237,19 @@ extension DyldCache {
235237
/// DyldCache containing unmapped local symbols
236238
public var symbolCache: DyldCache? {
237239
get throws {
240+
if let _symbolCache { return _symbolCache }
238241
guard header.hasProperty(\.symbolFileUUID),
239242
header.symbolFileUUID != .zero else {
240243
return nil
241244
}
242245
let suffix = ".symbols"
243246
let path = url.path + suffix
244-
return try .init(
247+
let symbolCache: DyldCache = try .init(
245248
subcacheUrl: .init(fileURLWithPath: path),
246249
mainCacheHeader: mainCacheHeader
247250
)
251+
_symbolCache = symbolCache
252+
return symbolCache
248253
}
249254
}
250255

Sources/MachOKit/FullDyldCache.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ public class FullDyldCache: DyldCacheRepresentable, _DyldCacheFileRepresentable
3131
public let url: URL
3232
let fileHandle: File
3333

34+
// Retain the symbol cache
35+
private var _symbolCache: DyldCache?
36+
3437
public var headerSize: Int {
3538
header.actualSize
3639
}
@@ -91,6 +94,7 @@ extension FullDyldCache {
9194
mainCache: nil
9295
)
9396
cache._fullCache = self
97+
cache._symbolCache = _symbolCache
9498
return cache
9599
}
96100

@@ -169,7 +173,10 @@ extension FullDyldCache {
169173
/// DyldCache containing unmapped local symbols
170174
public var symbolCache: DyldCache? {
171175
get throws {
172-
try mainCache.symbolCache
176+
if let _symbolCache = _symbolCache { return _symbolCache }
177+
let symbolCache = try mainCache.symbolCache
178+
_symbolCache = symbolCache
179+
return symbolCache
173180
}
174181
}
175182

0 commit comments

Comments
 (0)