-
Notifications
You must be signed in to change notification settings - Fork 3
feat: Preserve pointer types in generic iterators #409
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -156,23 +156,44 @@ func Generate(clients []any, dir string, opts ...Option) error { | |||||||||||||||||||
| return nil | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| func normalizeFullTypeName(typeName string) string { | ||||||||||||||||||||
| // Preserve pointer prefix | ||||||||||||||||||||
| prefix := "" | ||||||||||||||||||||
| if strings.HasPrefix(typeName, "*") { | ||||||||||||||||||||
| prefix = "*" | ||||||||||||||||||||
| typeName = typeName[1:] | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| versionPattern := regexp.MustCompile(`/v\d+\.`) | ||||||||||||||||||||
| parts := strings.Split(typeName, "/") | ||||||||||||||||||||
| importName := parts[len(parts)-1] | ||||||||||||||||||||
| if versionPattern.MatchString(typeName) { | ||||||||||||||||||||
| // Example typeName: github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/appconfiguration/armappconfiguration/v2.ConfigurationStoresClientCreateResponse | ||||||||||||||||||||
| importName = parts[len(parts)-2] + "." + strings.Split(parts[len(parts)-1], ".")[1] | ||||||||||||||||||||
|
Comment on lines
+170
to
+172
|
||||||||||||||||||||
| if versionPattern.MatchString(typeName) { | |
| // Example typeName: github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/appconfiguration/armappconfiguration/v2.ConfigurationStoresClientCreateResponse | |
| importName = parts[len(parts)-2] + "." + strings.Split(parts[len(parts)-1], ".")[1] | |
| if versionPattern.MatchString(typeName) && len(parts) >= 2 { | |
| // Example typeName: github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/appconfiguration/armappconfiguration/v2.ConfigurationStoresClientCreateResponse | |
| lastParts := strings.Split(parts[len(parts)-1], ".") | |
| if len(lastParts) >= 2 { | |
| importName = parts[len(parts)-2] + "." + lastParts[1] | |
| } |
murarustefaan marked this conversation as resolved.
Show resolved
Hide resolved
Copilot
AI
Feb 17, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The regex pattern is compiled on every function call. Since this function is called for each return type in method signatures, consider moving the regex compilation to a package-level variable to improve performance. For example, declare var genericTypePattern = regexp.MustCompile(\\[(.*)\]`)` at the package level and reuse it in this function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The regex pattern is compiled on every function call. Since this function may be called multiple times during code generation (once per type parameter), consider moving the regex compilation to a package-level variable to improve performance. For example, declare
var versionPattern = regexp.MustCompile(\/v\d+\.`)` at the package level and reuse it in this function.