Skip to content

Commit

Permalink
Merge pull request #2186 from onflow/bastian/optimize-structs
Browse files Browse the repository at this point in the history
  • Loading branch information
turbolent authored Dec 14, 2022
2 parents a3d496a + 11701cc commit cb7611b
Show file tree
Hide file tree
Showing 104 changed files with 683 additions and 689 deletions.
22 changes: 11 additions & 11 deletions encoding/json/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ func (e *Encoder) Encode(value cadence.Value) (err error) {
type jsonValue any

type jsonValueObject struct {
Type string `json:"type"`
Value jsonValue `json:"value"`
Type string `json:"type"`
}

type jsonEmptyValueObject struct {
Expand All @@ -122,8 +122,8 @@ type jsonCompositeValue struct {
}

type jsonCompositeField struct {
Name string `json:"name"`
Value jsonValue `json:"value"`
Name string `json:"name"`
}

type jsonPathLinkValue struct {
Expand All @@ -137,42 +137,42 @@ type jsonPathValue struct {
}

type jsonFieldType struct {
Id string `json:"id"`
Type jsonValue `json:"type"`
Id string `json:"id"`
}

type jsonNominalType struct {
Type jsonValue `json:"type"`
Kind string `json:"kind"`
TypeID string `json:"typeID"`
Fields []jsonFieldType `json:"fields"`
Initializers [][]jsonParameterType `json:"initializers"`
Type jsonValue `json:"type"`
}

type jsonSimpleType struct {
Kind string `json:"kind"`
}

type jsonUnaryType struct {
Kind string `json:"kind"`
Type jsonValue `json:"type"`
Kind string `json:"kind"`
}

type jsonConstantSizedArrayType struct {
Kind string `json:"kind"`
Type jsonValue `json:"type"`
Kind string `json:"kind"`
Size uint `json:"size"`
}

type jsonDictionaryType struct {
Kind string `json:"kind"`
KeyType jsonValue `json:"key"`
ValueType jsonValue `json:"value"`
Kind string `json:"kind"`
}

type jsonReferenceType struct {
Kind string `json:"kind"`
Type jsonValue `json:"type"`
Kind string `json:"kind"`
Authorized bool `json:"authorized"`
}

Expand All @@ -184,16 +184,16 @@ type jsonRestrictedType struct {
}

type jsonParameterType struct {
Type jsonValue `json:"type"`
Label string `json:"label"`
Id string `json:"id"`
Type jsonValue `json:"type"`
}

type jsonFunctionType struct {
Return jsonValue `json:"return"`
Kind string `json:"kind"`
TypeID string `json:"typeID"`
Parameters []jsonParameterType `json:"parameters"`
Return jsonValue `json:"return"`
}

type jsonTypeValue struct {
Expand All @@ -202,8 +202,8 @@ type jsonTypeValue struct {

type jsonStorageCapabilityValue struct {
Path jsonValue `json:"path"`
Address string `json:"address"`
BorrowType jsonValue `json:"borrowType"`
Address string `json:"address"`
}

type jsonFunctionValue struct {
Expand Down
2 changes: 1 addition & 1 deletion encoding/json/encoding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2543,9 +2543,9 @@ func TestDecodeFixedPoints(t *testing.T) {
}

type test struct {
check func(t *testing.T, actual cadence.Value, err error)
input string
expected int
check func(t *testing.T, actual cadence.Value, err error)
}

for ty, params := range allFixedPointTypes {
Expand Down
6 changes: 3 additions & 3 deletions runtime/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ func TestRuntimeTransaction_AddPublicKey(t *testing.T) {
var tests = []struct {
name string
code string
keyCount int
args []cadence.Value
expected [][]byte
keyCount int
}{
{
name: "Single key",
Expand Down Expand Up @@ -1220,11 +1220,11 @@ func newTestAccountKeyStorage() *testAccountKeyStorage {
}

type testAccountKeyStorage struct {
returnedKey *stdlib.AccountKey
events []cadence.Event
keys []*stdlib.AccountKey
unrevokedKeyCount int
returnedKey *stdlib.AccountKey
logs []string
unrevokedKeyCount int
}

func TestRuntimePublicKey(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions runtime/activations/activations.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ import (
// i.e. it can be used as a symbol table during semantic analysis,
// or as an activation record during interpretation or compilation.
type Activation[T any] struct {
MemoryGauge common.MemoryGauge
entries map[string]T
Depth int
Parent *Activation[T]
Depth int
IsFunction bool
MemoryGauge common.MemoryGauge
}

func NewActivation[T any](memoryGauge common.MemoryGauge, parent *Activation[T]) *Activation[T] {
Expand Down Expand Up @@ -113,8 +113,8 @@ func (a *Activation[T]) Set(name string, value T) {
// The current / most nested activation record can be found
// at the top of the stack (see function `Current`).
type Activations[T any] struct {
activations []*Activation[T]
memoryGauge common.MemoryGauge
activations []*Activation[T]
}

func NewActivations[T any](memoryGauge common.MemoryGauge) *Activations[T] {
Expand Down
6 changes: 3 additions & 3 deletions runtime/ast/argument.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ import (
)

type Argument struct {
Label string `json:",omitempty"`
Expression Expression
LabelStartPos *Position `json:",omitempty"`
LabelEndPos *Position `json:",omitempty"`
Label string `json:",omitempty"`
TrailingSeparatorPos Position
Expression Expression
}

func NewArgument(
Expand Down Expand Up @@ -75,8 +75,8 @@ func (a *Argument) String() string {
func (a *Argument) MarshalJSON() ([]byte, error) {
type Alias Argument
return json.Marshal(&struct {
Range
*Alias
Range
}{
Range: NewUnmeteredRangeFromPositioned(a),
Alias: (*Alias)(a),
Expand Down
6 changes: 3 additions & 3 deletions runtime/ast/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ func (b *Block) String() string {
func (b *Block) MarshalJSON() ([]byte, error) {
type Alias Block
return json.Marshal(&struct {
Type string
*Alias
Type string
}{
Type: "Block",
Alias: (*Alias)(b),
Expand Down Expand Up @@ -146,9 +146,9 @@ func (b *FunctionBlock) Walk(walkChild func(Element)) {
func (b *FunctionBlock) MarshalJSON() ([]byte, error) {
type Alias FunctionBlock
return json.Marshal(&struct {
*Alias
Type string
Range
*Alias
}{
Type: "FunctionBlock",
Range: b.Block.Range,
Expand Down Expand Up @@ -226,9 +226,9 @@ func (b *FunctionBlock) HasStatements() bool {
// Condition

type Condition struct {
Kind ConditionKind
Test Expression
Message Expression
Kind ConditionKind
}

func (c Condition) Doc() prettier.Doc {
Expand Down
28 changes: 14 additions & 14 deletions runtime/ast/composite.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ import (
// NOTE: For events, only an empty initializer is declared

type CompositeDeclaration struct {
Members *Members
DocString string
Conformances []*NominalType
Identifier Identifier
Range
Access Access
CompositeKind common.CompositeKind
Identifier Identifier
Conformances []*NominalType
Members *Members
DocString string
Range
}

var _ Element = &CompositeDeclaration{}
Expand Down Expand Up @@ -105,8 +105,8 @@ func (d *CompositeDeclaration) DeclarationDocString() string {
func (d *CompositeDeclaration) MarshalJSON() ([]byte, error) {
type Alias CompositeDeclaration
return json.Marshal(&struct {
Type string
*Alias
Type string
}{
Type: "CompositeDeclaration",
Alias: (*Alias)(d),
Expand Down Expand Up @@ -269,13 +269,13 @@ const (
// FieldDeclaration

type FieldDeclaration struct {
Access Access
Flags FieldDeclarationFlags
VariableKind VariableKind
Identifier Identifier
TypeAnnotation *TypeAnnotation
DocString string
Identifier Identifier
Range
Access Access
VariableKind VariableKind
Flags FieldDeclarationFlags
}

var _ Element = &FieldDeclaration{}
Expand Down Expand Up @@ -347,11 +347,11 @@ func (d *FieldDeclaration) DeclarationDocString() string {
func (d *FieldDeclaration) MarshalJSON() ([]byte, error) {
type Alias FieldDeclaration
return json.Marshal(&struct {
*Alias
Type string
Flags FieldDeclarationFlags `json:",omitempty"`
IsStatic bool
IsNative bool
*Alias
}{
Type: "FieldDeclaration",
Alias: (*Alias)(d),
Expand Down Expand Up @@ -457,10 +457,10 @@ func (d *FieldDeclaration) IsNative() bool {
// EnumCaseDeclaration

type EnumCaseDeclaration struct {
Access Access
Identifier Identifier
DocString string
Identifier Identifier
StartPos Position `json:"-"`
Access Access
}

var _ Element = &EnumCaseDeclaration{}
Expand Down Expand Up @@ -524,9 +524,9 @@ func (d *EnumCaseDeclaration) DeclarationDocString() string {
func (d *EnumCaseDeclaration) MarshalJSON() ([]byte, error) {
type Alias EnumCaseDeclaration
return json.Marshal(&struct {
*Alias
Type string
Range
*Alias
}{
Type: "EnumCaseDeclaration",
Range: NewUnmeteredRangeFromPositioned(d),
Expand Down
Loading

0 comments on commit cb7611b

Please sign in to comment.