Skip to content

Commit

Permalink
perf: correctly align struct fields
Browse files Browse the repository at this point in the history
  • Loading branch information
JanDeDobbeleer committed Aug 5, 2024
1 parent 32d4857 commit e37e365
Show file tree
Hide file tree
Showing 123 changed files with 584 additions and 672 deletions.
25 changes: 12 additions & 13 deletions src/cache/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,26 @@ import (
)

type Template struct {
Root bool
PWD string
AbsolutePWD string
Folder string
Shell string
Env map[string]string
SegmentsCache maps.Simple
Segments *maps.Concurrent
Var maps.Simple
ShellVersion string
AbsolutePWD string
UserName string
HostName string
Code int
Env map[string]string
Var maps.Simple
PWD string
Shell string
Folder string
OS string
WSL bool
Code int
PromptCount int
SHLVL int
Jobs int
Segments *maps.Concurrent
SegmentsCache maps.Simple

Initialized bool
sync.RWMutex
WSL bool
Root bool
Initialized bool
}

func (t *Template) AddSegmentData(key string, value any) {
Expand Down
2 changes: 1 addition & 1 deletion src/color/palette.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ func isPaletteKey(colorName Ansi) (Ansi, bool) {

// PaletteKeyError records the missing Palette key.
type PaletteKeyError struct {
Key Ansi
palette Palette
Key Ansi
}

func (p *PaletteKeyError) Error() string {
Expand Down
2 changes: 1 addition & 1 deletion src/color/palette_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ var (
type TestPaletteRequest struct {
Case string
Request Ansi
ExpectedError bool
Expected Ansi
ExpectedError bool
}

func TestPaletteShouldResolveColorFromTestPalette(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion src/color/palettes.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package color

type Palettes struct {
Template string `json:"template,omitempty" toml:"template,omitempty"`
List map[string]Palette `json:"list,omitempty" toml:"list,omitempty"`
Template string `json:"template,omitempty" toml:"template,omitempty"`
}
31 changes: 13 additions & 18 deletions src/config/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,19 @@ const (

// Block defines a part of the prompt with optional segments
type Block struct {
Type BlockType `json:"type,omitempty" toml:"type,omitempty"`
Alignment BlockAlignment `json:"alignment,omitempty" toml:"alignment,omitempty"`
Segments []*Segment `json:"segments,omitempty" toml:"segments,omitempty"`
Newline bool `json:"newline,omitempty" toml:"newline,omitempty"`
Filler string `json:"filler,omitempty" toml:"filler,omitempty"`
Overflow Overflow `json:"overflow,omitempty" toml:"overflow,omitempty"`

LeadingDiamond string `json:"leading_diamond,omitempty" toml:"leading_diamond,omitempty"`
TrailingDiamond string `json:"trailing_diamond,omitempty" toml:"trailing_diamond,omitempty"`

// Deprecated: keep the logic for legacy purposes
HorizontalOffset int `json:"horizontal_offset,omitempty" toml:"horizontal_offset,omitempty"`
VerticalOffset int `json:"vertical_offset,omitempty" toml:"vertical_offset,omitempty"`

MaxWidth int `json:"max_width,omitempty" toml:"max_width,omitempty"`
MinWidth int `json:"min_width,omitempty" toml:"min_width,omitempty"`

env runtime.Environment
env runtime.Environment
Type BlockType `json:"type,omitempty" toml:"type,omitempty"`
Alignment BlockAlignment `json:"alignment,omitempty" toml:"alignment,omitempty"`
Filler string `json:"filler,omitempty" toml:"filler,omitempty"`
Overflow Overflow `json:"overflow,omitempty" toml:"overflow,omitempty"`
LeadingDiamond string `json:"leading_diamond,omitempty" toml:"leading_diamond,omitempty"`
TrailingDiamond string `json:"trailing_diamond,omitempty" toml:"trailing_diamond,omitempty"`
Segments []*Segment `json:"segments,omitempty" toml:"segments,omitempty"`
VerticalOffset int `json:"vertical_offset,omitempty" toml:"vertical_offset,omitempty"`
HorizontalOffset int `json:"horizontal_offset,omitempty" toml:"horizontal_offset,omitempty"`
MaxWidth int `json:"max_width,omitempty" toml:"max_width,omitempty"`
MinWidth int `json:"min_width,omitempty" toml:"min_width,omitempty"`
Newline bool `json:"newline,omitempty" toml:"newline,omitempty"`
}

func (b *Block) Init(env runtime.Environment) {
Expand Down
4 changes: 2 additions & 2 deletions src/config/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
func TestBlockEnabled(t *testing.T) {
cases := []struct {
Case string
Expected bool
Segments []*Segment
Type BlockType
Segments []*Segment
Expected bool
}{
{Case: "line break block", Expected: true, Type: LineBreak},
{Case: "prompt enabled", Expected: true, Type: Prompt, Segments: []*Segment{{Enabled: true}}},
Expand Down
55 changes: 25 additions & 30 deletions src/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,41 +19,36 @@ const (

// Config holds all the theme for rendering the prompt
type Config struct {
Version int `json:"version" toml:"version"`
FinalSpace bool `json:"final_space,omitempty" toml:"final_space,omitempty"`
ConsoleTitleTemplate string `json:"console_title_template,omitempty" toml:"console_title_template,omitempty"`
TerminalBackground color.Ansi `json:"terminal_background,omitempty" toml:"terminal_background,omitempty"`
env runtime.Environment
Palette color.Palette `json:"palette,omitempty" toml:"palette,omitempty"`
DebugPrompt *Segment `json:"debug_prompt,omitempty" toml:"debug_prompt,omitempty"`
Var map[string]any `json:"var,omitempty" toml:"var,omitempty"`
Palettes *color.Palettes `json:"palettes,omitempty" toml:"palettes,omitempty"`
ValidLine *Segment `json:"valid_line,omitempty" toml:"valid_line,omitempty"`
SecondaryPrompt *Segment `json:"secondary_prompt,omitempty" toml:"secondary_prompt,omitempty"`
TransientPrompt *Segment `json:"transient_prompt,omitempty" toml:"transient_prompt,omitempty"`
ErrorLine *Segment `json:"error_line,omitempty" toml:"error_line,omitempty"`
ConsoleTitleTemplate string `json:"console_title_template,omitempty" toml:"console_title_template,omitempty"`
Format string `json:"-" toml:"-"`
origin string
PWD string `json:"pwd,omitempty" toml:"pwd,omitempty"`
AccentColor color.Ansi `json:"accent_color,omitempty" toml:"accent_color,omitempty"`
Output string `json:"-" toml:"-"`
TerminalBackground color.Ansi `json:"terminal_background,omitempty" toml:"terminal_background,omitempty"`
Cycle color.Cycle `json:"cycle,omitempty" toml:"cycle,omitempty"`
ITermFeatures terminal.ITermFeatures `json:"iterm_features,omitempty" toml:"iterm_features,omitempty"`
Blocks []*Block `json:"blocks,omitempty" toml:"blocks,omitempty"`
Tooltips []*Segment `json:"tooltips,omitempty" toml:"tooltips,omitempty"`
TransientPrompt *Segment `json:"transient_prompt,omitempty" toml:"transient_prompt,omitempty"`
ValidLine *Segment `json:"valid_line,omitempty" toml:"valid_line,omitempty"`
ErrorLine *Segment `json:"error_line,omitempty" toml:"error_line,omitempty"`
SecondaryPrompt *Segment `json:"secondary_prompt,omitempty" toml:"secondary_prompt,omitempty"`
DebugPrompt *Segment `json:"debug_prompt,omitempty" toml:"debug_prompt,omitempty"`
Palette color.Palette `json:"palette,omitempty" toml:"palette,omitempty"`
Palettes *color.Palettes `json:"palettes,omitempty" toml:"palettes,omitempty"`
Cycle color.Cycle `json:"cycle,omitempty" toml:"cycle,omitempty"`
ShellIntegration bool `json:"shell_integration,omitempty" toml:"shell_integration,omitempty"`
PWD string `json:"pwd,omitempty" toml:"pwd,omitempty"`
Var map[string]any `json:"var,omitempty" toml:"var,omitempty"`
EnableCursorPositioning bool `json:"enable_cursor_positioning,omitempty" toml:"enable_cursor_positioning,omitempty"`
PatchPwshBleed bool `json:"patch_pwsh_bleed,omitempty" toml:"patch_pwsh_bleed,omitempty"`
Version int `json:"version" toml:"version"`
DisableNotice bool `json:"disable_notice,omitempty" toml:"disable_notice,omitempty"`
AutoUpgrade bool `json:"auto_upgrade,omitempty" toml:"auto_upgrade,omitempty"`
ITermFeatures terminal.ITermFeatures `json:"iterm_features,omitempty" toml:"iterm_features,omitempty"`

// Deprecated
OSC99 bool `json:"osc99,omitempty" toml:"osc99,omitempty"`

Output string `json:"-" toml:"-"`
MigrateGlyphs bool `json:"-" toml:"-"`
Format string `json:"-" toml:"-"`

origin string
// eval bool
updated bool
env runtime.Environment
OSC99 bool `json:"osc99,omitempty" toml:"osc99,omitempty"`
ShellIntegration bool `json:"shell_integration,omitempty" toml:"shell_integration,omitempty"`
MigrateGlyphs bool `json:"-" toml:"-"`
PatchPwshBleed bool `json:"patch_pwsh_bleed,omitempty" toml:"patch_pwsh_bleed,omitempty"`
EnableCursorPositioning bool `json:"enable_cursor_positioning,omitempty" toml:"enable_cursor_positioning,omitempty"`
updated bool
FinalSpace bool `json:"final_space,omitempty" toml:"final_space,omitempty"`
}

func (cfg *Config) MakeColors() color.String {
Expand Down
2 changes: 1 addition & 1 deletion src/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ func TestGetPalette(t *testing.T) {
"blue": "#0000ff",
}
cases := []struct {
Case string
Palettes *color.Palettes
Palette color.Palette
ExpectedPalette color.Palette
Case string
}{
{
Case: "match",
Expand Down
22 changes: 11 additions & 11 deletions src/config/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ const (

func TestHasProperty(t *testing.T) {
cases := []struct {
Props properties.Map
Case string
Expected bool
Property properties.Property
Props properties.Map
Expected bool
}{
{Case: "Match", Expected: true, Property: Foo, Props: properties.Map{Foo: "bar"}},
{Case: "No Match", Expected: false, Property: Foo, Props: properties.Map{Bar: "foo"}},
Expand All @@ -40,10 +40,10 @@ func TestHasProperty(t *testing.T) {

func TestMigratePropertyValue(t *testing.T) {
cases := []struct {
Case string
Expected any
Property properties.Property
Props properties.Map
Case string
Property properties.Property
}{
{Case: "Match", Expected: "foo", Property: Foo, Props: properties.Map{Foo: "bar"}},
{Case: "No Match", Expected: nil, Property: Foo, Props: properties.Map{Bar: "foo"}},
Expand All @@ -59,11 +59,11 @@ func TestMigratePropertyValue(t *testing.T) {

func TestMigratePropertyKey(t *testing.T) {
cases := []struct {
Case string
Expected any
Props properties.Map
Case string
OldProperty properties.Property
NewProperty properties.Property
Props properties.Map
}{
{Case: "Match", Expected: "bar", OldProperty: Foo, NewProperty: Bar, Props: properties.Map{Foo: "bar"}},
{Case: "No match", Expected: nil, OldProperty: Foo, NewProperty: Bar, Props: properties.Map{FooBar: "bar"}},
Expand Down Expand Up @@ -95,10 +95,10 @@ func (m *MockedWriter) Init(_ properties.Properties, _ runtime.Environment) {}

func TestIconOverride(t *testing.T) {
cases := []struct {
Props properties.Map
Case string
Expected string
Property properties.Property
Props properties.Map
}{
{
Case: "Match",
Expand Down Expand Up @@ -133,13 +133,13 @@ func TestIconOverride(t *testing.T) {

func TestColorMigration(t *testing.T) {
cases := []struct {
Props properties.Map
Case string
Expected string
Property properties.Property
Template string
Background bool
NoOverride bool
Props properties.Map
}{
{
Case: "Foreground override",
Expand Down Expand Up @@ -191,10 +191,10 @@ func TestColorMigration(t *testing.T) {

func TestSegmentTemplateMigration(t *testing.T) {
cases := []struct {
Props properties.Map
Case string
Expected string
Type SegmentType
Props properties.Map
}{
{
Case: "GIT",
Expand Down Expand Up @@ -336,10 +336,10 @@ func TestSegmentTemplateMigration(t *testing.T) {

func TestInlineColorOverride(t *testing.T) {
cases := []struct {
Props properties.Map
Case string
Expected string
Property properties.Property
Props properties.Map
}{
{
Case: "Match",
Expand Down Expand Up @@ -374,9 +374,9 @@ func TestInlineColorOverride(t *testing.T) {

func TestMigratePreAndPostfix(t *testing.T) {
cases := []struct {
Props properties.Map
Case string
Expected string
Props properties.Map
}{
{
Case: "Pre and Postfix",
Expand Down
2 changes: 1 addition & 1 deletion src/config/responsive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import (

func TestShouldHideForWidth(t *testing.T) {
cases := []struct {
Error error
Case string
MinWidth int
MaxWidth int
Width int
Error error
Expected bool
}{
{Case: "No settings"},
Expand Down
50 changes: 23 additions & 27 deletions src/config/segment.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,41 +35,37 @@ func (s *SegmentStyle) resolve(env runtime.Environment, context any) SegmentStyl
}

type Segment struct {
Type SegmentType `json:"type,omitempty" toml:"type,omitempty"`
Tips []string `json:"tips,omitempty" toml:"tips,omitempty"`
Style SegmentStyle `json:"style,omitempty" toml:"style,omitempty"`
PowerlineSymbol string `json:"powerline_symbol,omitempty" toml:"powerline_symbol,omitempty"`
writer SegmentWriter
env runtime.Environment
Properties properties.Map `json:"properties,omitempty" toml:"properties,omitempty"`
LeadingPowerlineSymbol string `json:"leading_powerline_symbol,omitempty" toml:"leading_powerline_symbol,omitempty"`
InvertPowerline bool `json:"invert_powerline,omitempty" toml:"invert_powerline,omitempty"`
ForegroundTemplates template.List `json:"foreground_templates,omitempty" toml:"foreground_templates,omitempty"`
BackgroundTemplates template.List `json:"background_templates,omitempty" toml:"background_templates,omitempty"`
Background color.Ansi `json:"background" toml:"background"`
Style SegmentStyle `json:"style,omitempty" toml:"style,omitempty"`
Text string `json:"-" toml:"-"`
name string
LeadingDiamond string `json:"leading_diamond,omitempty" toml:"leading_diamond,omitempty"`
TrailingDiamond string `json:"trailing_diamond,omitempty" toml:"trailing_diamond,omitempty"`
Template string `json:"template,omitempty" toml:"template,omitempty"`
Templates template.List `json:"templates,omitempty" toml:"templates,omitempty"`
Foreground color.Ansi `json:"foreground" toml:"foreground"`
TemplatesLogic template.Logic `json:"templates_logic,omitempty" toml:"templates_logic,omitempty"`
Properties properties.Map `json:"properties,omitempty" toml:"properties,omitempty"`
Interactive bool `json:"interactive,omitempty" toml:"interactive,omitempty"`
PowerlineSymbol string `json:"powerline_symbol,omitempty" toml:"powerline_symbol,omitempty"`
Filler string `json:"filler,omitempty" toml:"filler,omitempty"`
Alias string `json:"alias,omitempty" toml:"alias,omitempty"`
MaxWidth int `json:"max_width,omitempty" toml:"max_width,omitempty"`
Type SegmentType `json:"type,omitempty" toml:"type,omitempty"`
styleCache SegmentStyle
CacheDuration cache.Duration `json:"cache_duration,omitempty" toml:"cache_duration,omitempty"`
BackgroundTemplates template.List `json:"background_templates,omitempty" toml:"background_templates,omitempty"`
ForegroundTemplates template.List `json:"foreground_templates,omitempty" toml:"foreground_templates,omitempty"`
Tips []string `json:"tips,omitempty" toml:"tips,omitempty"`
Templates template.List `json:"templates,omitempty" toml:"templates,omitempty"`
MinWidth int `json:"min_width,omitempty" toml:"min_width,omitempty"`
Filler string `json:"filler,omitempty" toml:"filler,omitempty"`
Background color.Ansi `json:"background" toml:"background"`
Foreground color.Ansi `json:"foreground" toml:"foreground"`
MaxWidth int `json:"max_width,omitempty" toml:"max_width,omitempty"`
Duration time.Duration `json:"-" toml:"-"`
NameLength int `json:"-" toml:"-"`
Interactive bool `json:"interactive,omitempty" toml:"interactive,omitempty"`
Enabled bool `json:"-" toml:"-"`
Newline bool `json:"newline,omitempty" toml:"newline,omitempty"`
CacheDuration cache.Duration `json:"cache_duration,omitempty" toml:"cache_duration,omitempty"`

Enabled bool `json:"-" toml:"-"`
Text string `json:"-" toml:"-"`

env runtime.Environment
writer SegmentWriter
styleCache SegmentStyle
name string

// debug info
Duration time.Duration `json:"-" toml:"-"`
NameLength int `json:"-" toml:"-"`
InvertPowerline bool `json:"invert_powerline,omitempty" toml:"invert_powerline,omitempty"`
}

func (segment *Segment) Name() string {
Expand Down
4 changes: 2 additions & 2 deletions src/config/segment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ func TestShouldIncludeFolder(t *testing.T) {
func TestGetColors(t *testing.T) {
cases := []struct {
Case string
Background bool
Expected color.Ansi
Templates []string
Default color.Ansi
Region string
Profile string
Templates []string
Background bool
}{
{Case: "No template - foreground", Expected: "color", Background: false, Default: "color"},
{Case: "No template - background", Expected: "color", Background: true, Default: "color"},
Expand Down
Loading

0 comments on commit e37e365

Please sign in to comment.