Skip to content

Commit 47cacfc

Browse files
Renamed internal load methods to be more consistent
1 parent c44fdd2 commit 47cacfc

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

Sources/CodableDatastore/Datastore/Datastore.swift

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ extension Datastore {
263263
/// Create any missing indexes and prime the datastore for writing.
264264
try await transaction.apply(descriptor: updatedDescriptor, for: key)
265265

266-
let primaryIndex = _load(IndexRange(), order: .ascending, awaitWarmup: false)
266+
let primaryIndex = _load(range: IndexRange(), order: .ascending, awaitWarmup: false)
267267

268268
let versionData = try Data(self.version)
269269

@@ -505,7 +505,7 @@ extension Datastore {
505505
/// - awaitWarmup: Whether the sequence should await warmup or jump right into loading.
506506
/// - Returns: An asynchronous sequence containing the instances matching the range of values in that sequence.
507507
nonisolated func _load(
508-
_ identifierRange: some IndexRangeExpression<IdentifierType> & Sendable,
508+
range identifierRange: some IndexRangeExpression<IdentifierType> & Sendable,
509509
order: RangeOrder,
510510
awaitWarmup: Bool
511511
) -> some TypedAsyncSequence<(id: IdentifierType, instance: InstanceType)> & Sendable {
@@ -519,7 +519,10 @@ extension Datastore {
519519
options: [.readOnly]
520520
) { transaction, _ in
521521
do {
522-
try await transaction.primaryIndexScan(range: identifierRange.applying(order), datastoreKey: self.key) { versionData, instanceData in
522+
try await transaction.primaryIndexScan(
523+
range: identifierRange.applying(order),
524+
datastoreKey: self.key
525+
) { versionData, instanceData in
523526
let entryVersion = try Version(versionData)
524527
let decoder = try await self.decoder(for: entryVersion)
525528
let decodedValue = try await decoder(instanceData)
@@ -544,7 +547,7 @@ extension Datastore {
544547
_ identifierRange: some IndexRangeExpression<IdentifierType> & Sendable,
545548
order: RangeOrder = .ascending
546549
) -> some TypedAsyncSequence<InstanceType> & Sendable where IdentifierType: RangedIndexable {
547-
_load(identifierRange, order: order, awaitWarmup: true)
550+
_load(range: identifierRange, order: order, awaitWarmup: true)
548551
.map { $0.instance }
549552
}
550553

@@ -574,24 +577,24 @@ extension Datastore {
574577
_ unboundedRange: Swift.UnboundedRange,
575578
order: RangeOrder = .ascending
576579
) -> some TypedAsyncSequence<InstanceType> & Sendable {
577-
_load(IndexRange(), order: order, awaitWarmup: true)
580+
_load(range: IndexRange.unbounded, order: order, awaitWarmup: true)
578581
.map { $0.instance }
579582
}
580583

581584
/// **Internal:** Load a range of instances from a given index as an async sequence.
582585
/// - Parameters:
586+
/// - index: The index to load from.
583587
/// - range: The range to load.
584588
/// - order: The order to process instances in.
585-
/// - index: The index to load from.
586589
/// - Returns: An asynchronous sequence containing the instances matching the range of values in that sequence.
587590
@usableFromInline
588591
nonisolated func _load<
589592
Index: IndexRepresentation<InstanceType>,
590593
Bound: Indexable
591594
>(
592-
_ range: some IndexRangeExpression<Bound> & Sendable,
593-
order: RangeOrder = .ascending,
594-
from index: KeyPath<Format, Index>
595+
index: KeyPath<Format, Index>,
596+
range: some IndexRangeExpression<Bound> & Sendable,
597+
order: RangeOrder = .ascending
595598
) -> some TypedAsyncSequence<InstanceType> & Sendable {
596599
let declaredIndex = self.indexRepresentations[AnyIndexRepresentation(indexRepresentation: self.format[keyPath: index])]
597600

@@ -659,7 +662,7 @@ extension Datastore {
659662
order: RangeOrder = .ascending,
660663
from index: KeyPath<Format, Index>
661664
) -> some TypedAsyncSequence<InstanceType> & Sendable {
662-
_load(IndexRange(only: value), order: order, from: index)
665+
_load(index: index, range: IndexRange(only: value), order: order)
663666
}
664667

665668
/// Load an instance with the matching indexed value, or return nil if one is not found.
@@ -676,7 +679,7 @@ extension Datastore {
676679
_ value: Value,
677680
from index: KeyPath<Format, Index>
678681
) async throws -> InstanceType? {
679-
try await _load(IndexRange(only: value), from: index).first(where: { _ in true })
682+
try await _load(index: index, range: IndexRange(only: value)).first(where: { _ in true })
680683
}
681684

682685
/// Load a range of instances from a given index as an async sequence.
@@ -697,7 +700,7 @@ extension Datastore {
697700
order: RangeOrder = .ascending,
698701
from index: KeyPath<Format, Index>
699702
) -> some TypedAsyncSequence<InstanceType> & Sendable {
700-
_load(range, order: order, from: index)
703+
_load(index: index, range: range, order: order)
701704
}
702705

703706
/// Load a range of instances from a given index as an async sequence.
@@ -719,7 +722,7 @@ extension Datastore {
719722
order: RangeOrder = .ascending,
720723
from index: KeyPath<Format, Index>
721724
) -> some TypedAsyncSequence<InstanceType> & Sendable {
722-
_load(range, order: order, from: index)
725+
_load(index: index, range: range, order: order)
723726
}
724727

725728
/// Load all instances in a datastore in index order as an async sequence.
@@ -737,7 +740,7 @@ extension Datastore {
737740
order: RangeOrder = .ascending,
738741
from index: KeyPath<Format, Index>
739742
) -> some TypedAsyncSequence<InstanceType> & Sendable {
740-
_load(IndexRange.unbounded, order: order, from: index)
743+
_load(index: index, range: IndexRange.unbounded, order: order)
741744
}
742745
}
743746

Sources/CodableDatastore/Indexes/IndexRangeExpression.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ extension IndexRangeExpression {
6868
)
6969
}
7070

71+
@usableFromInline
7172
static var unbounded: IndexRange<Bound> {
7273
IndexRange()
7374
}

0 commit comments

Comments
 (0)