From c784c8ecb1760b674f438b065d1912d18fe201e6 Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Sat, 8 Aug 2026 20:57:05 +0200 Subject: [PATCH] lib.log.log(): Use .join() to build argument string The argument string builder in log() previously iterated with enumerate and checked per-iteration whether to prepend a space. Replace the loop with ' '.join(str(a) for a in args), which is a single C-level operation. Move the leading-space logic after the only_printable block so the regex transformations see the raw joined content. Signed-off-by: Jan Lindemann --- src/python/jw/pkg/lib/log.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/python/jw/pkg/lib/log.py b/src/python/jw/pkg/lib/log.py index 57f38b09..0c6276f2 100644 --- a/src/python/jw/pkg/lib/log.py +++ b/src/python/jw/pkg/lib/log.py @@ -229,13 +229,14 @@ def log( # export margs = '' if len(args): - for i, a in enumerate(args): - margs += (' ' if (i or (msg and not msg.endswith(' '))) else '') + str(a) + margs = ' '.join(str(a) for a in args) if only_printable: margs = _special_char_regex.sub( lambda mo: _special_chars[mo.string[mo.start():mo.end()]], margs ) margs = re.sub('[\x01-\x1f]', '.', margs) + if msg and not msg.endswith(' '): + margs = ' ' + margs for file in _log_file_streams: print(msg + _clean_log_prefix + margs, file = file)