8000
Skip to content

unnecessary Layout() calls in SetDisplay and other Set* methods #83

Description

@imicky

Use case: I frequently need to toggle the visibility of several views based on certain conditions. This results in many calls to SetDisplay() with the same value during a single frame.

I noticed that many Set* methods (SetDisplay, SetWidth, SetHeight, etc.) trigger Layout() unconditionally, even when the new value equals the current one. Not sure if this causes any significant performance degradation, but it's clearly wasteful.

furex-ui/view.go

Lines 377 to 381 in 0995989

// SetDisplay sets the display property of the view.
func (v *View) SetDisplay(display Display) {
v.Display = display
v.Layout()
}

Proposed fix: add an early return if unchanged:

func (v *View) SetDisplay(display Display) {
    if v.Display == display { return }
    v.Display = display
    v.Layout()
}

Would a PR covering all relevant Set* methods be welcome?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    0