Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Sources/MachOKit/MachOFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ public class MachOFile: MachORepresentable {
// Retain the cache to which `self` belongs
private var _fullCache: FullDyldCache?
private var _cache: DyldCache?
// Memoizes whether the lazy `cache` getter has already tried
// `DyldCache.init(url:)`. A standalone (non-cache) MachOFile fails that
// init and leaves `_cache` nil, which is indistinguishable from "not yet
// attempted", so without this flag every `cache` access re-opens and
// re-parses the file from disk.
private var _cacheResolutionAttempted = false

// Cache for chained fixups lookup
private var _chainedFixupsCache: DyldChainedFixups?
Expand Down Expand Up @@ -637,7 +643,9 @@ extension MachOFile {
if let _fullCache {
return _fullCache.cache(for: url)
}
if _cacheResolutionAttempted { return nil }
_cache = try? .init(url: url)
_cacheResolutionAttempted = true
return _cache
}

Expand Down