diff options
| author | Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com> | 2026-08-26 13:15:59 +0200 |
|---|---|---|
| committer | Rob Herring (Arm) <robh@kernel.org> | 2026-08-31 08:23:17 -0500 |
| commit | e1945a960f35b17bcbcea55dabca76384f6321d4 (patch) | |
| tree | 2386eba0398441e20349e49028d8841f8d3b5e52 /scripts | |
| parent | 7e17fa6b828385aaa6602d032a51041c30bcdcff (diff) | |
dtc: dt-check-style: Call _strip_strings_and_comments() only once
More than one rule evaluates pure code - stripped from comments and
indentation - thus store this pure code in DtsLine class for
better performance.
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
Link: https://patch.msgid.link/20260826-n-dts-style-checker-continued-v6-7-f270b1e81f8e@oss.qualcomm.com
Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/dtc/dt-check-style | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/scripts/dtc/dt-check-style b/scripts/dtc/dt-check-style index b71e6bf815a7..43069fc1fac9 100755 --- a/scripts/dtc/dt-check-style +++ b/scripts/dtc/dt-check-style @@ -79,18 +79,19 @@ def is_preprocessor(stripped): class DtsLine: - __slots__ = ('lineno', 'raw', 'linetype', 'indent_str', 'stripped', 'is_root', + __slots__ = ('lineno', 'raw', 'code', 'linetype', 'indent_str', 'stripped', 'is_root', 'prop_name', 'continuations', 'node_name', 'node_addr', 'label', 'ref_name', 'parent', 'depth', 'closures') def __init__(self, lineno, raw, linetype, depth, indent_str, stripped, is_root = False): self.lineno = lineno # 1-based within the block - self.raw = raw + self.raw = raw # Entire raw line self.linetype = linetype self.indent_str = indent_str # leading whitespace as-is self.depth = depth - self.stripped = stripped + self.stripped = stripped # Code without indentation + self.code = _strip_strings_and_comments(stripped) # Only the code, skipping trailing comments self.is_root = is_root self.prop_name = None self.continuations = [] @@ -811,8 +812,7 @@ def check_hex_case(ctx): LineType.COMMENT_START, LineType.COMMENT_BODY, LineType.COMMENT_END, LineType.PREPROCESSOR): continue - text = _strip_strings_and_comments(dl.raw) - for m in re.finditer(r'\b0[xX][0-9a-fA-F]+\b', text): + for m in re.finditer(r'\b0[xX][0-9a-fA-F]+\b', dl.code): lit = m.group(0) if any(c.isupper() for c in lit[2:]) or lit[1] == 'X': yield (dl.lineno, @@ -860,9 +860,9 @@ def check_value_whitespace(ctx): for dl in ctx.lines: if dl.linetype != LineType.PROPERTY: continue - segs = [_strip_strings_and_comments(dl.raw).strip()] + segs = [dl.code.strip()] for cont in dl.continuations: - segs.append(_strip_strings_and_comments(cont.stripped).strip()) + segs.append(cont.code.strip()) text = '' for s in segs: if not s: @@ -895,8 +895,7 @@ def check_node_close_alone(ctx): LineType.COMMENT_START, LineType.COMMENT_BODY, LineType.COMMENT_END, LineType.PREPROCESSOR): continue - text = _strip_strings_and_comments(dl.raw) - if '};' in text: + if '};' in dl.code: yield (dl.lineno, 'closing brace must be on its own line') |
