Skip to content

Commit

Permalink
Short-circuit for better performance
Browse files Browse the repository at this point in the history
  • Loading branch information
dfed committed Jan 20, 2024
1 parent 32ebe59 commit a9f94a7
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions Sources/SafeDICore/Generators/ScopeGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -246,18 +246,27 @@ actor ScopeGenerator {

private func generateProperties(leadingMemberWhitespace: String) async throws -> [String] {
guard var orderedPropertiesToGenerate = List(propertiesToGenerate) else { return [] }
let propertiesToGenerate = Set(propertiesToGenerate.compactMap(\.property))
for propertyToGenerateNode in orderedPropertiesToGenerate {
let hasDependenciesGeneratedByCurrentScope = !propertyToGenerateNode
.value
.requiredReceivedProperties
.isDisjoint(with: propertiesToGenerate)
guard hasDependenciesGeneratedByCurrentScope else {
// This property does not have received dependencies generated by this scope,
// Therefore its ordering is irrelevant.
continue
}
var lastDependency: List<ScopeGenerator>?
for nextPropertyToGenerate in propertyToGenerateNode.dropFirst() {
guard let nextProperty = nextPropertyToGenerate.value.property else {
continue
}
let propertyToGenerateDependsOnNextProperty = propertyToGenerateNode
.value
.requiredReceivedProperties
.contains(nextProperty)

if propertyToGenerateDependsOnNextProperty {
if
let nextProperty = nextPropertyToGenerate.value.property,
// The property to generate depends on the next property!
propertyToGenerateNode
.value
.requiredReceivedProperties
.contains(nextProperty)
{
lastDependency = nextPropertyToGenerate
}
}
Expand Down

0 comments on commit a9f94a7

Please sign in to comment.