From patchwork Fri Apr 14 18:37:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philip Prindeville X-Patchwork-Id: 1769166 X-Patchwork-Delegate: lynxis@fe80.eu Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=YWL51Mrx; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Pylcb4bc8z23rS for ; Sat, 15 Apr 2023 04:40:15 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=22yiHY5b1eb7H+RGDacKdNWmvNcdEYTIlpoliDTgG0Y=; b=YWL51MrxpwwPSJ 9Ur8e17mkzj6R2k7og1s/a3YQx6ta8koWNgG3SpT/+d6dNqnqCPxxH+rA89Aq1LsUUcV0q1FTwLzL DDcOuGmU/A6jq7/5CqwD9BC0Qtb2/jAYWwUA7KNxbl9wa22Cia6K7HSQr4n58JSWpj9R+gx7ziUN6 zpVxgcm93gA0ggIHYxtOyNPXipNIFMk+spX0EyxhZ5frGFg79A6rBOe6rvhjqwJkRK1vzW59WdLNz KGvijGgaT/8H2SaGuM7eBJ8VrSDR/YW/U5qnJjKXyqYOGPYn+6Ee12fF4AquAgrIhp1ne3w+5C1ue +Eo/Mf7oLGAWI6/JlmrQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pnOIQ-00ANlQ-2x; Fri, 14 Apr 2023 18:37:18 +0000 Received: from mail.redfish-solutions.com ([24.116.100.90]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pnOIM-00ANiR-2Q for openwrt-devel@lists.openwrt.org; Fri, 14 Apr 2023 18:37:16 +0000 Received: from ubuntu22.redfish-solutions.com (ubuntu22.redfish-solutions.com [192.168.8.33]) (authenticated bits=0) by mail.redfish-solutions.com (8.17.1/8.16.1) with ESMTPSA id 33EIb6cX275013 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 14 Apr 2023 12:37:06 -0600 From: "Philip Prindeville" To: openwrt-devel@lists.openwrt.org Cc: Philip Prindeville Subject: [PATCH 2/2] blobmsg: Don't do at run-time what can be done at compile-time Date: Fri, 14 Apr 2023 12:37:06 -0600 Message-Id: <20230414183706.1531155-1-philipp@redfish-solutions.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.3 on 192.168.8.3 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230414_113714_881408_388FCE24 X-CRM114-Status: UNSURE ( 9.17 ) X-CRM114-Notice: Please train this message. X-Spam-Score: 0.0 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: From: Philip Prindeville Repeatedly calling a run-time function like strlen() on an invariant value is inefficient, especially if that value can be computed once (at initialization) or better yet, computed at compile-time. Content analysis details: (0.0 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org From: Philip Prindeville Repeatedly calling a run-time function like strlen() on an invariant value is inefficient, especially if that value can be computed once (at initialization) or better yet, computed at compile-time. Signed-off-by: Philip Prindeville --- blobmsg_json.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/blobmsg_json.c b/blobmsg_json.c index dce81e991ef7b83ac4906bca6f875369d3057f36..ec8b482c30c96a355aca58651632bc509a16bedf 100644 --- a/blobmsg_json.c +++ b/blobmsg_json.c @@ -151,15 +151,15 @@ static bool blobmsg_puts(struct strbuf *s, const char *c, int len) static void add_separator(struct strbuf *s) { - const char *indent_chars = "\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t"; + const char indent_chars[] = "\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t"; size_t len; if (!s->indent) return; len = s->indent_level + 1; - if (len > strlen(indent_chars)) - len = strlen(indent_chars); + if (len > sizeof(indent_chars) - 1) + len = sizeof(indent_chars) - 1; blobmsg_puts(s, indent_chars, len); }