From patchwork Wed Oct 23 06:39:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rolf Eike Beer X-Patchwork-Id: 13846543 Received: from mx1.emlix.com (mx1.emlix.com [178.63.209.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DADA314A4DE; Wed, 23 Oct 2024 06:39:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.63.209.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729665560; cv=none; b=k+j01SbA4K8Z627xsY2nCEdkWmtPDp4THPxxEh5wnl2DyvBTFSpbLxqwwBBTtr9WWe8KlvBejZUlCBVN/szEm/1BSUfEVvAdsFdFrEGMEnZ5SBgHk9kPYo0JbpoRTPHghSmlza/h2+X7vhUzwZXONKdgeTtsEEe/cn89MbEGL9E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729665560; c=relaxed/simple; bh=XYMrAKGPn3G7hN4PF2Z2mZGMRGRjPfTIzYJUmtHmcjI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Z3Ie80G6QE5/WDk1nAJ7oAwR3vKnnf+FYcJBn8EzBSpagA2mK/63Mk8tjbWuAjf437WCXmx2OErhcqCIx0D0sIXy3dcAUV4Ivrl/Sb0LhEDq6QNPzMC2vggKpbzpg+LUFRfSmRNL2zDCnpean7YTj+e/QFyNFCMFN1IUHHEsAgw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=emlix.com; spf=pass smtp.mailfrom=emlix.com; arc=none smtp.client-ip=178.63.209.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=emlix.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=emlix.com Received: from mailer.emlix.com (p5098be52.dip0.t-ipconnect.de [80.152.190.82]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.emlix.com (Postfix) with ESMTPS id 0C2EE5F8A7; Wed, 23 Oct 2024 08:39:16 +0200 (CEST) From: Rolf Eike Beer To: Masahiro Yamada Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 7/7] kconfig: qconf: simplify character replacement Date: Wed, 23 Oct 2024 08:39:15 +0200 Message-ID: <3592638.iIbC2pHGDl@devpool47.emlix.com> Organization: emlix GmbH In-Reply-To: <4960180.31r3eYUQgx@devpool47.emlix.com> References: <4960180.31r3eYUQgx@devpool47.emlix.com> Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Replace the hand crafted lookup table with a QHash. This has the nice benefit that the added offsets can not get out of sync with the length of the replacement strings. Signed-off-by: Rolf Eike Beer --- scripts/kconfig/qconf.cc | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/scripts/kconfig/qconf.cc b/scripts/kconfig/qconf.cc index 4b2f707c9203..f07a463c5760 100644 --- a/scripts/kconfig/qconf.cc +++ b/scripts/kconfig/qconf.cc @@ -1123,28 +1123,19 @@ QString ConfigInfoView::print_filter(const QString &str) { QRegularExpression re("[<>&\"\\n]"); QString res = str; + + QHash patterns; + patterns['<'] = "<"; + patterns['>'] = ">"; + patterns['&'] = "&"; + patterns['"'] = """; + patterns['\n'] = "
"; + for (int i = 0; (i = res.indexOf(re, i)) >= 0;) { - switch (res[i].toLatin1()) { - case '<': - res.replace(i, 1, "<"); - i += 4; - break; - case '>': - res.replace(i, 1, ">"); - i += 4; - break; - case '&': - res.replace(i, 1, "&"); - i += 5; - break; - case '"': - res.replace(i, 1, """); - i += 6; - break; - case '\n': - res.replace(i, 1, "
"); - i += 4; - break; + const QString n = patterns.value(res[i], QString()); + if (!n.isEmpty()) { + res.replace(i, 1, n); + i += n.length(); } } return res;