Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Fanduzi opened this issue Apr 16, 2022 · 0 comments

Comments

@Fanduzi
Copy link

Fanduzi commented Apr 16, 2022

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant