refactor: use slices.Contains to simplify code (#536)

Signed-off-by: vastonus <vastonus@outlook.com>
This commit is contained in:
vastonus 2025-10-16 19:57:01 +08:00 committed by GitHub
parent ed672b2bc9
commit f575e91b2c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 4 additions and 5 deletions

View File

@ -17,6 +17,7 @@ import (
"net"
"os"
"regexp"
"slices"
"sort"
"strings"
@ -450,11 +451,9 @@ func makeTemplate(md *desc.MessageDescriptor, path []*desc.MessageDescriptor) pr
dm := dynamic.NewMessage(md)
// if the message is a recursive structure, we don't want to blow the stack
for _, seen := range path {
if seen == md {
// already visited this type; avoid infinite recursion
return dm
}
if slices.Contains(path, md) {
// already visited this type; avoid infinite recursion
return dm
}
path = append(path, dm.GetMessageDescriptor())