Skip to content

Commit

Permalink
Merge pull request #109 from evgfedotov/fix/oneof-bytes
Browse files Browse the repository at this point in the history
fix: ResetVT oneof
  • Loading branch information
vmg authored Nov 17, 2023
2 parents 5a1a54c + 93e4d89 commit 641a874
Show file tree
Hide file tree
Showing 4 changed files with 178 additions and 19 deletions.
12 changes: 7 additions & 5 deletions features/pool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (p *pool) message(message *protogen.Message) {

p.P(`var vtprotoPool_`, ccTypeName, ` = `, p.Ident("sync", "Pool"), `{`)
p.P(`New: func() interface{} {`)
p.P(`return &`, message.GoIdent, `{}`)
p.P(`return &`, ccTypeName, `{}`)
p.P(`},`)
p.P(`}`)

Expand All @@ -68,10 +68,12 @@ func (p *pool) message(message *protogen.Message) {
}
p.P(fmt.Sprintf("f%d", len(saved)), ` := m.`, fieldName, `[:0]`)
saved = append(saved, field)
} else if field.Oneof != nil && p.ShouldPool(message) && p.ShouldPool(field.Message) {
p.P(`if oneof, ok := m.`, field.Oneof.GoName, `.(*`, field.GoIdent, `); ok {`)
p.P(`oneof.`, fieldName, `.ReturnToVTPool()`)
p.P(`}`)
} else if field.Oneof != nil {
if p.ShouldPool(field.Message) {
p.P(`if oneof, ok := m.`, field.Oneof.GoName, `.(*`, field.GoIdent, `); ok {`)
p.P(`oneof.`, fieldName, `.ReturnToVTPool()`)
p.P(`}`)
}
} else {
switch field.Desc.Kind() {
case protoreflect.MessageKind, protoreflect.GroupKind:
Expand Down
44 changes: 30 additions & 14 deletions testproto/pool/pool_with_oneof.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions testproto/pool/pool_with_oneof.proto
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ message OneofTest {
Test1 test1 = 1;
Test2 test2 = 2;
Test3 test3 = 3;
bytes test4 = 4;
}
}
140 changes: 140 additions & 0 deletions testproto/pool/pool_with_oneof_vtproto.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 641a874

Please sign in to comment.