Skip to content

Commit

Permalink
protoc-gen-swift: hasRecursiveField -> hasRecursiveSingularField
Browse files Browse the repository at this point in the history
  • Loading branch information
ydnar committed Sep 17, 2019
1 parent 65ff2df commit e0c482f
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions Sources/protoc-gen-swift/MessageGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class MessageGenerator {
// when the message has one or more oneof{}s. As that will efficively
// reduce the real number of fields and the message might not need heap
// storage yet.
let useHeapStorage = isAnyMessage || descriptor.fields.count > 16 || hasRecursiveField(descriptor: descriptor)
let useHeapStorage = isAnyMessage || descriptor.fields.count > 16 || hasRecursiveSingularField(descriptor: descriptor)

oneofs = descriptor.oneofs.map {
return OneofGenerator(descriptor: $0, generatorOptions: generatorOptions, namer: namer, usesHeapStorage: useHeapStorage)
Expand Down Expand Up @@ -506,19 +506,20 @@ fileprivate func hasSingleMessageField(descriptor: Descriptor) -> Bool {
return result
}

fileprivate func hasRecursiveField(descriptor: Descriptor, visited: [Descriptor] = []) -> Bool {
fileprivate func hasRecursiveSingularField(descriptor: Descriptor, visited: [Descriptor] = []) -> Bool {
var visited = visited
visited.append(descriptor)
return descriptor.fields.contains {
if $0.type != .message {
// Repeated fields use heap storage already
if ($0.type != .message && $0.type != .group) || $0.label == .repeated {
return false
}
guard let messageType = $0.messageType else {
return false
}
return visited.contains {
$0 === messageType
} || hasRecursiveField(descriptor: messageType, visited: visited)
} || hasRecursiveSingularField(descriptor: messageType, visited: visited)
}
}

Expand Down

0 comments on commit e0c482f

Please sign in to comment.