From a7ffc02c340b33c4c00761d094a41e08d3ad1abb Mon Sep 17 00:00:00 2001 From: Jake Kenneally Date: Tue, 3 Feb 2026 19:43:44 -0500 Subject: [PATCH] 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. --- lib/Epub/Epub/css/CssParser.cpp | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/lib/Epub/Epub/css/CssParser.cpp b/lib/Epub/Epub/css/CssParser.cpp index afcf7e95..2ccaafe9 100644 --- a/lib/Epub/Epub/css/CssParser.cpp +++ b/lib/Epub/Epub/css/CssParser.cpp @@ -382,14 +382,10 @@ CssStyle CssParser::parseDeclarations(const std::string& declBlock) { // Shorthand: 1-4 values for top, right, bottom, left const auto values = splitWhitespace(propValue); if (!values.empty()) { - const CssLength top = interpretLength(values[0]); - const CssLength right = values.size() >= 2 ? interpretLength(values[1]) : top; - const CssLength bottom = values.size() >= 3 ? interpretLength(values[2]) : top; - const CssLength left = values.size() >= 4 ? interpretLength(values[3]) : right; - style.marginTop = top; - style.marginRight = right; - style.marginBottom = bottom; - style.marginLeft = left; + style.marginTop = interpretLength(values[0]); + style.marginRight = values.size() >= 2 ? interpretLength(values[1]) : style.marginTop; + style.marginBottom = values.size() >= 3 ? interpretLength(values[2]) : style.marginTop; + style.marginLeft = values.size() >= 4 ? interpretLength(values[3]) : style.marginRight; style.defined.marginTop = style.defined.marginRight = style.defined.marginBottom = style.defined.marginLeft = 1; } } 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 const auto values = splitWhitespace(propValue); if (!values.empty()) { - const CssLength top = interpretLength(values[0]); - const CssLength right = values.size() >= 2 ? interpretLength(values[1]) : top; - const CssLength bottom = values.size() >= 3 ? interpretLength(values[2]) : top; - const CssLength left = values.size() >= 4 ? interpretLength(values[3]) : right; - style.paddingTop = top; - style.paddingRight = right; - style.paddingBottom = bottom; - style.paddingLeft = left; + style.paddingTop = interpretLength(values[0]); + style.paddingRight = values.size() >= 2 ? interpretLength(values[1]) : style.paddingTop; + style.paddingBottom = values.size() >= 3 ? interpretLength(values[2]) : style.paddingTop; + style.paddingLeft = values.size() >= 4 ? interpretLength(values[3]) : style.paddingRight; style.defined.paddingTop = style.defined.paddingRight = style.defined.paddingBottom = style.defined.paddingLeft = 1; }