Skip to content

Commit

Permalink
fix: create pointer instead of value to improve performance
Browse files Browse the repository at this point in the history
Signed-off-by: Junjie Gao <junjiegao@microsoft.com>
  • Loading branch information
JeyJeyGao committed Aug 3, 2023
1 parent 1465e3e commit 91a3691
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions internal/encoding/asn1/asn1.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,19 @@ func decode(r []byte) (value, error) {

// primitive value
if isPrimitive(identifier) {
return primitiveValue{
return &primitiveValue{
identifier: identifier,
content: r[:contentLen],
}, nil
}
// constructed value
rootConstructed := constructedValue{
rootConstructed := &constructedValue{
identifier: identifier,
rawContent: r[:contentLen],
}

// start depth-first decoding with stack
valueStack := []*constructedValue{&rootConstructed}
valueStack := []*constructedValue{rootConstructed}
for len(valueStack) > 0 {
stackLen := len(valueStack)
// top
Expand All @@ -110,21 +110,21 @@ func decode(r []byte) (value, error) {
}
if isPrimitive(identifier) {
// primitive value
primitiveNode := primitiveValue{
primitiveNode := &primitiveValue{
identifier: identifier,
content: node.rawContent[:contentLen],
}
node.members = append(node.members, &primitiveNode)
node.members = append(node.members, primitiveNode)
} else {
// constructed value
constructedNode := constructedValue{
constructedNode := &constructedValue{
identifier: identifier,
rawContent: node.rawContent[:contentLen],
}
node.members = append(node.members, &constructedNode)
node.members = append(node.members, constructedNode)

// add a new constructed node to the stack
valueStack = append(valueStack, &constructedNode)
valueStack = append(valueStack, constructedNode)
}
node.rawContent = node.rawContent[contentLen:]
}
Expand Down

0 comments on commit 91a3691

Please sign in to comment.