Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp1706691pxb; Sat, 4 Sep 2021 19:22:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwvfE6v6m8ESrm4x56YLqDN3eCL2/j0VIh/Mms9IMRFZQouSYYIFqGUy8dBBkIqtbljymeS X-Received: by 2002:a17:907:8309:: with SMTP id mq9mr6708818ejc.561.1630808552055; Sat, 04 Sep 2021 19:22:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630808552; cv=none; d=google.com; s=arc-20160816; b=b6Gz9EmAxJvm8h13ZNSonj8+E9ov90Oy34hrQA2L4dAVWVbxy5QMXvLH526suNXo2T zSqSmuKqgwEr2G42cQrnA1Zpt03eAWlKbyQFfPgI+d8oZOmbYGzb+TA5GQG2nemkquBm SxWbK1uZRFGKeexO5VB0AdbgnGQvfOrM8SDqE785TykXgop9xFj++sGPUaMXyOTfyeds RWbmw/RD24jvvLTUipeOn4XjxrPkdO9UGn5d5NxvIbvObScx3KeseRqoJGQkxPB5fuDR ODYp0HQlAsGiyfIZ+U9EsKDjrDtd6+oxzlO9yIl8lja1hrxsw4ZkOqL8kx7iJoyX6xSC wTDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:to:from:subject:message-id; bh=HoRbEsChvRbsusimqbPY79u5fkPfc9DL/syId57H0N4=; b=0ViIRIxjF2JKKAO8ereRfrVtE5zmg2SDoNwwlCrgzs+ZAH0Hc/pgCQIcFgnN20zOkv 9VIT7qUxga0teDlHN7/DwmIRxEYjhH7rqv5PYWg78Rb3gRaed7cE9/9TJokPB+b/OE02 z7xlWTz66Cr73fAi/Zy9WcM95B8E9Eqd9xgilo4Vfo5lWHoeOQnv+XLdzgscgf7DVnhF nam4IkWBrrMXeh6I5EK3jo0zdHXFM941b7C/bWZ3m3OUBsSxxT0ta5XZc3PWItZO9Ev0 RAHk+NWfi7bJ29KxrZ1ZCTuhsWmOGTC+ZG2okcaCW/nmmeaQfdaI17mWPBX2WXf2KGDf hvdQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z14si4002837ejl.487.2021.09.04.19.22.07; Sat, 04 Sep 2021 19:22:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232140AbhIEBhu (ORCPT + 99 others); Sat, 4 Sep 2021 21:37:50 -0400 Received: from smtprelay0057.hostedemail.com ([216.40.44.57]:37962 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S230185AbhIEBht (ORCPT ); Sat, 4 Sep 2021 21:37:49 -0400 Received: from omf06.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay06.hostedemail.com (Postfix) with ESMTP id 85004180F3235; Sun, 5 Sep 2021 01:36:46 +0000 (UTC) Received: from [HIDDEN] (Authenticated sender: joe@perches.com) by omf06.hostedemail.com (Postfix) with ESMTPA id 3DBBF2448B4; Sun, 5 Sep 2021 01:36:42 +0000 (UTC) Message-ID: Subject: Re: [PATCH v2 1/2] lib: add sputchar() helper From: Joe Perches To: Yury Norov , Petr Mladek , Andrew Morton , Andy Shevchenko , Bartosz Golaszewski , Chris Down , Gilles Muller , Ingo Molnar , Jacob Keller , Julia Lawall , Michal Marek , Nicolas Palix , Peter Zijlstra , Rasmus Villemoes , Sergey Senozhatsky , Stephen Boyd , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, cocci@systeme.lip6.fr Date: Sat, 04 Sep 2021 18:36:41 -0700 In-Reply-To: <20210904231020.331185-2-yury.norov@gmail.com> References: <20210904231020.331185-1-yury.norov@gmail.com> <20210904231020.331185-2-yury.norov@gmail.com> Content-Type: text/plain; charset="ISO-8859-1" User-Agent: Evolution 3.40.0-1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspamout01 X-Rspamd-Queue-Id: 3DBBF2448B4 X-Spam-Status: No, score=-1.13 X-Stat-Signature: t98tkm18ypq3owe69faj3w56jk9yhahf X-Session-Marker: 6A6F6540706572636865732E636F6D X-Session-ID: U2FsdGVkX1+VM8n5Kky5gQP7FnH2SvXr4BaHweLyZOU= X-HE-Tag: 1630805802-980154 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 2021-09-04 at 16:10 -0700, Yury Norov wrote: > There are 47 occurrences of the code snippet like this: > if (buf < end) > *buf = ' '; > ++buf; > > This patch adds a helper function sputchar() to replace opencoding. > It adds a lot to readability, and also saves 43 bytes of text on x86. I think this patch does little to improve readability. Perhaps make it void and use something like sputchar(*buf++, end, ); Though the sputchar name doesn't seems particularly intelligible. > +static inline char *sputchar(char *buf, const char *end, char c) > +{ > + if (buf < end) > + *buf = c; > + > + return buf + 1; > +} > + > ?/* > ??* General tracing related utility functions - trace_printk(), > ??* tracing_on/tracing_off and tracing_start()/tracing_stop > diff --git a/lib/string_helpers.c b/lib/string_helpers.c [] > @@ -335,12 +335,8 @@ static bool escape_space(unsigned char c, char **dst, char *end) > ? return false; > ? } > > - if (out < end) > - *out = '\\'; > - ++out; > - if (out < end) > - *out = to; > - ++out; > + out = sputchar(out, end, '\\'); > + out = sputchar(out, end, to); etc...