refactor: simplify CssParser margin/padding shorthand

Remove intermediary variables (top, right, bottom, left) in margin and
padding shorthand parsing. Directly assign to style fields and reference
previously assigned values for defaulting logic.

No functional change - purely code simplification.
This commit is contained in:
Jake Kenneally 2026-02-03 19:43:44 -05:00
parent d564173949
commit a7ffc02c34

View File

@ -382,14 +382,10 @@ CssStyle CssParser::parseDeclarations(const std::string& declBlock) {
// Shorthand: 1-4 values for top, right, bottom, left // Shorthand: 1-4 values for top, right, bottom, left
const auto values = splitWhitespace(propValue); const auto values = splitWhitespace(propValue);
if (!values.empty()) { if (!values.empty()) {
const CssLength top = interpretLength(values[0]); style.marginTop = interpretLength(values[0]);
const CssLength right = values.size() >= 2 ? interpretLength(values[1]) : top; style.marginRight = values.size() >= 2 ? interpretLength(values[1]) : style.marginTop;
const CssLength bottom = values.size() >= 3 ? interpretLength(values[2]) : top; style.marginBottom = values.size() >= 3 ? interpretLength(values[2]) : style.marginTop;
const CssLength left = values.size() >= 4 ? interpretLength(values[3]) : right; style.marginLeft = values.size() >= 4 ? interpretLength(values[3]) : style.marginRight;
style.marginTop = top;
style.marginRight = right;
style.marginBottom = bottom;
style.marginLeft = left;
style.defined.marginTop = style.defined.marginRight = style.defined.marginBottom = style.defined.marginLeft = 1; style.defined.marginTop = style.defined.marginRight = style.defined.marginBottom = style.defined.marginLeft = 1;
} }
} else if (propName == "padding-top") { } else if (propName == "padding-top") {
@ -408,14 +404,10 @@ CssStyle CssParser::parseDeclarations(const std::string& declBlock) {
// Shorthand: 1-4 values for top, right, bottom, left // Shorthand: 1-4 values for top, right, bottom, left
const auto values = splitWhitespace(propValue); const auto values = splitWhitespace(propValue);
if (!values.empty()) { if (!values.empty()) {
const CssLength top = interpretLength(values[0]); style.paddingTop = interpretLength(values[0]);
const CssLength right = values.size() >= 2 ? interpretLength(values[1]) : top; style.paddingRight = values.size() >= 2 ? interpretLength(values[1]) : style.paddingTop;
const CssLength bottom = values.size() >= 3 ? interpretLength(values[2]) : top; style.paddingBottom = values.size() >= 3 ? interpretLength(values[2]) : style.paddingTop;
const CssLength left = values.size() >= 4 ? interpretLength(values[3]) : right; style.paddingLeft = values.size() >= 4 ? interpretLength(values[3]) : style.paddingRight;
style.paddingTop = top;
style.paddingRight = right;
style.paddingBottom = bottom;
style.paddingLeft = left;
style.defined.paddingTop = style.defined.paddingRight = style.defined.paddingBottom = style.defined.paddingTop = style.defined.paddingRight = style.defined.paddingBottom =
style.defined.paddingLeft = 1; style.defined.paddingLeft = 1;
} }