[light] Eliminate redundant clamp in LightCall::validate_() and normalize_color()

After clamp_and_log_if_invalid() clamps the value in-place, the
LightColorValues setter's clamp() is guaranteed to be a no-op. For 5
of 9 fields the compiler was inlining the setter's clamp, generating
~18 bytes of redundant float compare + conditional move per field.

Use friend access to assign directly to LightColorValues fields,
bypassing the setter. Also apply the same optimization to
normalize_color() where division by max_value guarantees results
stay in [0,1].
This commit is contained in:
J. Nick Koston
2026-02-10 21:01:34 -06:00
parent e3fbbb2e99
commit 0b02476e8a

View File

@@ -95,15 +95,18 @@ class LightColorValues {
*/
void normalize_color() {
if (this->color_mode_ & ColorCapability::RGB) {
float max_value = fmaxf(this->get_red(), fmaxf(this->get_green(), this->get_blue()));
float max_value = fmaxf(this->red_, fmaxf(this->green_, this->blue_));
// Assign directly to avoid redundant clamp in set_red/green/blue.
// Values are guaranteed in [0,1]: inputs are already clamped to [0,1],
// and dividing by max_value (the largest) keeps results in [0,1].
if (max_value == 0.0f) {
this->set_red(1.0f);
this->set_green(1.0f);
this->set_blue(1.0f);
this->red_ = 1.0f;
this->green_ = 1.0f;
this->blue_ = 1.0f;
} else {
this->set_red(this->get_red() / max_value);
this->set_green(this->get_green() / max_value);
this->set_blue(this->get_blue() / max_value);
this->red_ /= max_value;
this->green_ /= max_value;
this->blue_ /= max_value;
}
}
}