Skip to content

Add memoization to Color parsing and serialization methods #1277

@obiot

Description

@obiot

Description

The Color class methods for parsing and serializing color values could benefit from memoization to avoid redundant computation:

Parsing (cache by input):

  • parseRGB() — parses "rgb(...)" / "rgba(...)" strings
  • parseHex() — parses "#RRGGBB" / "#RRGGBBAA" hex strings

Serialization (cache by r,g,b,a state, invalidate on change):

  • toHex() — returns "#RRGGBB"
  • toHex8() — returns "#RRGGBBAA"
  • toRGB() — returns "rgb(R,G,B)"
  • toRGBA() — returns "rgba(R,G,B,A)"

For serialization, the cache should be invalidated whenever r, g, b, or a values change (e.g. via setColor, parseHex, etc.).

Context

These were tracked as inline TODO comments in src/math/color.ts. Moved to a ticket for better visibility and tracking.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions