Skip to content

Commit 8d834e2

Browse files
committed
Pack the models.Commit struct a little tighter
Change the base type of some of our enums from int to uint8, and reorder fields for better packing. This reduces the size of models.Commit from 152 to 132 bytes on my machine. This doesn't improve overall memory usage significantly, but why not save a little bit of memory if it's easy.
1 parent 722cc85 commit 8d834e2

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

pkg/commands/models/commit.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
// Special commit hash for empty tree object
1212
const EmptyTreeCommitHash = "4b825dc642cb6eb9a060e54bf8d69288fbee4904"
1313

14-
type CommitStatus int
14+
type CommitStatus uint8
1515

1616
const (
1717
StatusNone CommitStatus = iota
@@ -30,7 +30,7 @@ const (
3030
ActionNone todo.TodoCommand = 0
3131
)
3232

33-
type Divergence int
33+
type Divergence uint8
3434

3535
// For a divergence log (left/right comparison of two refs) this is set to
3636
// either DivergenceLeft or DivergenceRight for each commit; for normal
@@ -45,17 +45,18 @@ const (
4545
type Commit struct {
4646
hash *string
4747
Name string
48-
Status CommitStatus
49-
Action todo.TodoCommand
5048
Tags []string
5149
ExtraInfo string // something like 'HEAD -> master, tag: v0.15.2'
5250
AuthorName string // something like 'Jesse Duffield'
5351
AuthorEmail string // something like '[email protected]'
5452
UnixTimestamp int64
55-
Divergence Divergence // set to DivergenceNone unless we are showing the divergence view
5653

5754
// Hashes of parent commits (will be multiple if it's a merge commit)
5855
parents []*string
56+
57+
Status CommitStatus
58+
Action todo.TodoCommand
59+
Divergence Divergence // set to DivergenceNone unless we are showing the divergence view
5960
}
6061

6162
type NewCommitOpts struct {

0 commit comments

Comments
 (0)