mirror of
https://github.com/zeromicro/go-zero.git
synced 2026-05-10 16:30:01 +08:00
perf: pre-allocate all known length arrays to avoid re-scaling (#5029)
Co-authored-by: Kevin Wan <wanjunfeng@gmail.com>
This commit is contained in:
committed by
GitHub
parent
a2b98dbcf7
commit
130e1ba963
@@ -126,7 +126,7 @@ func (v *ApiVisitor) VisitTypeLit(ctx *api.TypeLitContext) any {
|
||||
// VisitTypeBlock implements from api.BaseApiParserVisitor
|
||||
func (v *ApiVisitor) VisitTypeBlock(ctx *api.TypeBlockContext) any {
|
||||
list := ctx.AllTypeBlockBody()
|
||||
var types []TypeExpr
|
||||
types := make([]TypeExpr, 0, len(list))
|
||||
for _, each := range list {
|
||||
types = append(types, each.Accept(v).(TypeExpr))
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ func (p parser) fillTypes() error {
|
||||
for _, item := range p.ast.Type {
|
||||
switch v := (item).(type) {
|
||||
case *ast.TypeStruct:
|
||||
var members []spec.Member
|
||||
members := make([]spec.Member, 0, len(v.Fields))
|
||||
for _, item := range v.Fields {
|
||||
members = append(members, p.fieldToMember(item))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user