Skip to content

Commit

Permalink
batch allocate constants
Browse files Browse the repository at this point in the history
  • Loading branch information
zdyj3170101136 committed Aug 1, 2023
1 parent 2aa0b33 commit 1dcd969
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
7 changes: 7 additions & 0 deletions parser/chunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,13 @@ func (c *Chunk) Parse(r io.Reader, options *ChunkParseOptions) (err error) {
func buildClasses(metadata MetadataEvent) ClassMap {
classes := make(map[int]ClassMetadata)
for _, class := range metadata.Root.Metadata.Classes {
var numConstants int
for _, field := range class.Fields {
if field.ConstantPool {
numConstants++
}
}
class.numConstants = numConstants
classes[int(class.ID)] = class
}

Expand Down
15 changes: 8 additions & 7 deletions parser/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,14 @@ func (f *FieldMetadata) AppendChild(name string) Element {
}

type ClassMetadata struct {
ID int64
Name string
SuperType string
SimpleType bool
Fields []FieldMetadata
Settings []SettingMetadata
Annotations []AnnotationMetadata
ID int64
Name string
SuperType string
SimpleType bool
Fields []FieldMetadata
Settings []SettingMetadata
Annotations []AnnotationMetadata
numConstants int
}

func (c *ClassMetadata) SetAttribute(key, value string) (err error) {
Expand Down
3 changes: 3 additions & 0 deletions parser/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ func appendConstant(r reader.Reader, constants *[]constant, name string, class i
}

func parseFields(r reader.Reader, classes ClassMap, cpools PoolMap, class ClassMetadata, constants *[]constant, resolved bool, cb func(reader.Reader, string, ParseResolvable) error) error {
if constants != nil && class.numConstants != 0 && !resolved {
*constants = make([]constant, 0, class.numConstants)
}
for _, f := range class.Fields {
if f.ConstantPool {
if constants != nil && !resolved {
Expand Down

0 comments on commit 1dcd969

Please sign in to comment.