Skip to content

The results for fieldalignment and structslop are not the same. Who is better? #52

@Fanduzi

Description

@Fanduzi
package main

type Car struct {
	flag        bool
	age         int32
	F1          int8
	age2        int32
	age3        int16
	F2          int64
	F3          *int32
	InnerStruct struct {
		InnerByte byte
		//InnerStr string
	}
	F4   []byte
	Name string
	F5   error
}

func main() {

}

fieldalignment

fieldalignment -fix main.go  
/Users/TiM/Downloads/GolandProjects/helloworld/main.go:3:10: struct of size 104 could be 88

fieldalignment result

type Car struct {
	F5          error
	F3          *int32
	Name        string
	F4          []byte
	F2          int64
	age         int32
	age2        int32
	age3        int16
	flag        bool
	InnerStruct struct{ InnerByte byte }
	F1          int8
}

structslop

structslop -apply main.go     
/Users/TiM/Downloads/GolandProjects/helloworld/main.go:3:10: struct has size 104 (size class 112), could be 88 (size class 96), you'll save 14.29% if you rearrange it to:
struct {
        F4          []byte
        Name        string
        F5          error
        F3          *int32
        F2          int64
        age         int32
        age2        int32
        age3        int16
        flag        bool
        InnerStruct struct{ InnerByte byte }
        F1          int8
}

structslop result

type Car struct {
        F4          []byte
        Name        string
        F5          error
        F3          *int32
        F2          int64
        age         int32
        age2        int32
        age3        int16
        flag        bool
        InnerStruct struct{ InnerByte byte }
        F1          int8
}

The results for fieldalignment and structslop are not the same

test the under Car with fieldalignment

type Car struct {
        F4          []byte
        Name        string
        F5          error
        F3          *int32
        F2          int64
        age         int32
        age2        int32
        age3        int16
        flag        bool
        InnerStruct struct{ InnerByte byte }
        F1          int8
}
fieldalignment -fix main.go
/Users/TiM/Downloads/GolandProjects/helloworld/main.go:3:10: struct with 64 pointer bytes could be 48

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions