Skip to content

Commit

Permalink
cache typeFn in ClassMetadata
Browse files Browse the repository at this point in the history
  • Loading branch information
zdyj3170101136 committed Aug 1, 2023
1 parent 1dcd969 commit 5660ef6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
8 changes: 8 additions & 0 deletions parser/chunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,14 @@ func buildClasses(metadata MetadataEvent) ClassMap {
numConstants++
}
}

if typeFn, ok := types[class.Name]; ok {
class.typeFn = typeFn
} else {
class.typeFn = func() ParseResolvable {
return &UnsupportedType{}
}
}
class.numConstants = numConstants
classes[int(class.ID)] = class
}
Expand Down
1 change: 1 addition & 0 deletions parser/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ type ClassMetadata struct {
Settings []SettingMetadata
Annotations []AnnotationMetadata
numConstants int
typeFn func() ParseResolvable
}

func (c *ClassMetadata) SetAttribute(key, value string) (err error) {
Expand Down
7 changes: 1 addition & 6 deletions parser/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,7 @@ func ParseClass(r reader.Reader, classes ClassMap, cpools PoolMap, classID int64
if !ok {
return nil, fmt.Errorf("unexpected class %d", classID)
}
var v ParseResolvable
if typeFn, ok := types[class.Name]; ok {
v = typeFn()
} else {
v = new(UnsupportedType)
}
v := class.typeFn()
if err := v.Parse(r, classes, cpools, class); err != nil {
return nil, err
}
Expand Down

0 comments on commit 5660ef6

Please sign in to comment.