Skip to content

Commit

Permalink
Merge pull request #73 from p-x9/feature/conform-random-access-collec…
Browse files Browse the repository at this point in the history
…tion

Conform to `RandomAccessCollection` protocol
  • Loading branch information
p-x9 authored Apr 10, 2024
2 parents 31f36cc + f4e863b commit 847fcfd
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Sources/MachOKit/MachOFile+CodeSign.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ extension MachOFile.CodeSign {

public func blobIndices(
of superBlob: CodeSignSuperBlob
) -> AnySequence<CodeSignBlobIndex> {
) -> AnyRandomAccessCollection<CodeSignBlobIndex> {
superBlob.blobIndices(in: self)
}
}
6 changes: 3 additions & 3 deletions Sources/MachOKit/MachOFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ extension MachOFile {
}

extension MachOFile {
public var dataInCode: AnySequence<DataInCodeEntry>? {
public var dataInCode: AnyRandomAccessCollection<DataInCodeEntry>? {
guard let dataInCode = loadCommands.dataInCode,
dataInCode.datasize > 0 else {
return nil
Expand All @@ -367,7 +367,7 @@ extension MachOFile {
)

if isSwapped {
return AnySequence(
return AnyRandomAccessCollection(
entries.lazy.map {
DataInCodeEntry(
layout: .init(
Expand All @@ -380,7 +380,7 @@ extension MachOFile {
)
}

return AnySequence(entries)
return AnyRandomAccessCollection(entries)
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/MachOKit/MachOImage+CodeSign.swift
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ extension MachOImage.CodeSign {

public func blobIndices(
of superBlob: CodeSignSuperBlob
) -> AnySequence<CodeSignBlobIndex> {
) -> AnyRandomAccessCollection<CodeSignBlobIndex> {
superBlob.blobIndices(in: self)
}
}
8 changes: 4 additions & 4 deletions Sources/MachOKit/Model/Codesign/CodeSignSuperBlob.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ extension CodeSignSuperBlob {
/// - Returns: indices of this superBlob
public func blobIndices(
in signature: MachOFile.CodeSign
) -> AnySequence<CodeSignBlobIndex> {
) -> AnyRandomAccessCollection<CodeSignBlobIndex> {
let offset = offset + layoutSize

return AnySequence(
return AnyRandomAccessCollection(
DataSequence<CS_BlobIndex>(
data: signature.data.advanced(by: offset),
numberOfElements: count
Expand All @@ -50,10 +50,10 @@ extension CodeSignSuperBlob {
/// - Returns: indices of this superBlob
public func blobIndices(
in signature: MachOImage.CodeSign
) -> AnySequence<CodeSignBlobIndex> {
) -> AnyRandomAccessCollection<CodeSignBlobIndex> {
let offset = offset + layoutSize

return AnySequence(
return AnyRandomAccessCollection(
MemorySequence<CS_BlobIndex>(
basePointer: signature.basePointer
.advanced(by: offset)
Expand Down
16 changes: 8 additions & 8 deletions Sources/MachOKit/Model/DyldCache/DyldCacheLocalSymbolsInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ extension DyldCacheLocalSymbolsInfo {
)
}

public func symbols(in cache: DyldCache) -> AnySequence<MachOFile.Symbol> {
public func symbols(in cache: DyldCache) -> AnyRandomAccessCollection<MachOFile.Symbol> {
if let symbols64 = symbols64(in: cache) {
return AnySequence(symbols64)
return AnyRandomAccessCollection(symbols64)
} else if let symbols32 = symbols32(in: cache) {
return AnySequence(symbols32)
return AnyRandomAccessCollection(symbols32)
} else {
return AnySequence([])
return AnyRandomAccessCollection([])
}
}
}
Expand Down Expand Up @@ -96,21 +96,21 @@ extension DyldCacheLocalSymbolsInfo {

public func entries(
in cache: DyldCache
) -> AnySequence<DyldCacheLocalSymbolsEntryProtocol> {
) -> AnyRandomAccessCollection<DyldCacheLocalSymbolsEntryProtocol> {
if let entries = entries64(in: cache) {
return AnySequence(
return AnyRandomAccessCollection(
entries
.lazy
.map { $0 as DyldCacheLocalSymbolsEntryProtocol }
)
} else if let entries = entries32(in: cache) {
return AnySequence(
return AnyRandomAccessCollection(
entries
.lazy
.map { $0 as DyldCacheLocalSymbolsEntryProtocol }
)
} else {
return AnySequence([])
return AnyRandomAccessCollection([])
}
}
}
2 changes: 1 addition & 1 deletion Sources/MachOKit/Protocol/CodeSignProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public protocol CodeSignProtocol {
/// - Returns: indices of superBlob
func blobIndices(
of superBlob: CodeSignSuperBlob
) -> AnySequence<CodeSignBlobIndex>
) -> AnyRandomAccessCollection<CodeSignBlobIndex>
}

extension CodeSignProtocol {
Expand Down
2 changes: 1 addition & 1 deletion Sources/MachOKit/Protocol/MachORepresentable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public protocol MachORepresentable {
associatedtype ExportTrieEntries: Sequence<ExportTrieEntry>
associatedtype Strings: Sequence<StringTableEntry>
associatedtype FunctionStarts: Sequence<FunctionStart>
associatedtype DataInCode: Sequence<DataInCodeEntry>
associatedtype DataInCode: RandomAccessCollection<DataInCodeEntry>
associatedtype DyldChainedFixups: DyldChainedFixupsProtocol
associatedtype CodeSign: CodeSignProtocol

Expand Down

0 comments on commit 847fcfd

Please sign in to comment.