Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp7024748ybn; Mon, 30 Sep 2019 07:33:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqybeZsVFk7r47MPI/jlsZVUur/9QAnFz1se27jN/US3EudoFmk9MSTJ+uZ45Z/hcf3Z0G3r X-Received: by 2002:aa7:d48f:: with SMTP id b15mr20082199edr.159.1569853982744; Mon, 30 Sep 2019 07:33:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569853982; cv=none; d=google.com; s=arc-20160816; b=FUbjom1xDYYmqDU0r6UdaKbNaInU2tt+ligt1JLymwyjAoO2SDRvdEgAq71m5vHePu i3Py5u1zTg9jyfKF8XkWCE8jOlxB9uM/bCnFv2EOqUPl4LG60tiDUs/z85tOqb6x7+mS 5dsj4mBKdXQ/y7vXzJFUN4o2f3Y+YLtqvc+lj+eB8IyApyLmcrJVtAv9JYFcQ/xygtaN pjg6xOOE2z6eHvjVJaVZkYg2Wm0YP2TSRfNX0pfyf6/reIrPPOa0p+reCQ8gCjG7v2Ik lEEaedwYnm7sNaAr8agbE1a4VZZvnmF7/tCkM/830B4nUYAceag9HVC8lyxKj/CFv6t5 7fYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=zBL7epC00p9U9++zGccJDAwUuYYIfHYJAHuYq0NGhKI=; b=Y95nbm1jXT6JANBXZWqi/KWwH/y4Ppf7FqmsJrjTJBWsqr767TLf3mAyEAhC7+9ycM CzqGvJ6vhZPV3OLpJl+CosUqdpkYeiHjSeTkgCmcz+ByyPBOtM7/jKFGzc4wBmBPlR0c wE47ZpPe0F31xND2bTc6lyBa03SHFaQ2TkfUP/ll9294YHADAJJuHg1Nbi0ypmU+DOcR OWlCdOp5ITTkD4nxcXiH85Ev3PWOngALtpf8tFPZZLDitB0pUBs0HucuVWmxOBWhncli bXk40/syRsUpatS4hK6I/BEnkhdfGfcwjKJTZFcOPwzKSyCCVSP/DhZSXYbdC5jKzK8M KMfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=Ke+Nx55i; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y3si7606636ede.38.2019.09.30.07.32.36; Mon, 30 Sep 2019 07:33:02 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=Ke+Nx55i; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731736AbfI3ObH (ORCPT + 99 others); Mon, 30 Sep 2019 10:31:07 -0400 Received: from mail-lj1-f194.google.com ([209.85.208.194]:32901 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730902AbfI3ObG (ORCPT ); Mon, 30 Sep 2019 10:31:06 -0400 Received: by mail-lj1-f194.google.com with SMTP id a22so9751788ljd.0 for ; Mon, 30 Sep 2019 07:31:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=zBL7epC00p9U9++zGccJDAwUuYYIfHYJAHuYq0NGhKI=; b=Ke+Nx55iXZQfZSHRoqDLY786VnrQjJgoe/GD/uOlYu8+tDQ9EAUgLcqHGlUm6BTKpb WX5654MwqqZ+4GZEY92XR6gll89SPNvhOQD60cXDcMBMQxuvCBnI/oi+9OcSMb9YhvVR U2f3yCuw6i91i3dKrEsYVFk1FGdpYawZKGy0M= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=zBL7epC00p9U9++zGccJDAwUuYYIfHYJAHuYq0NGhKI=; b=ubSpMFFlPhWu9GKDyHiKxj2bojJeYSAA8XDjsxCsWo4dJ6RakxQp10js/w/9Gb/zEk nqejsFdPMmkpkroevNnxqC/f2N7R/8rNQSDB/yeypueqCwHwapKP7dhV4bg+v8kkxlGl z68/35jHI1l+bfmfI3hLihMfywSOnxWh7n9r7wJgaliHIwUbFMcgzCU2HAKanp9IDoIz nYUoSwnF4I1qTIxO18AphefY8IYMuMW62wZQ6upmYp1j9E7tyWaI30nBN3EJd+LusXai rV/pMmuZCW+lui2y2ibQ+J0Ux+7uIDyd9uLyltBu1wf4zal8ukcaAbhAgeGy/VYQE1fD tAJA== X-Gm-Message-State: APjAAAUil/0dNauZS/U/TTCaqVbLdtniIlarkTQAwz2nmCInAaDBLyj3 KtW7rElQAy08S9IVL+K9lt5c1Q== X-Received: by 2002:a2e:8ec6:: with SMTP id e6mr12257813ljl.231.1569853864490; Mon, 30 Sep 2019 07:31:04 -0700 (PDT) Received: from [172.16.11.28] ([81.216.59.226]) by smtp.gmail.com with ESMTPSA id q11sm3301932lje.52.2019.09.30.07.31.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 Sep 2019 07:31:03 -0700 (PDT) Subject: Re: [PATCH v2] lib/string-choice: add yesno(), onoff(), enableddisabled(), plural() helpers To: Jani Nikula , linux-kernel@vger.kernel.org Cc: Joonas Lahtinen , Rodrigo Vivi , intel-gfx@lists.freedesktop.org, Vishal Kulkarni , netdev@vger.kernel.org, Greg Kroah-Hartman , linux-usb@vger.kernel.org, Andrew Morton , Julia Lawall References: <20190930141842.15075-1-jani.nikula@intel.com> From: Rasmus Villemoes Message-ID: <8e697984-03b5-44f3-304e-42d303724eaa@rasmusvillemoes.dk> Date: Mon, 30 Sep 2019 16:31:02 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <20190930141842.15075-1-jani.nikula@intel.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 30/09/2019 16.18, Jani Nikula wrote: > The kernel has plenty of ternary operators to choose between constant > strings, such as condition ? "yes" : "no", as well as value == 1 ? "" : > "s": > > > --- > > v2: add string-choice.[ch] to not clutter kernel.h and to actually save > space on string constants. > > +EXPORT_SYMBOL(enableddisabled); > + > +const char *plural(long v) > +{ > + return v == 1 ? "" : "s"; > +} > +EXPORT_SYMBOL(plural); > Say what? I'll bet you a beer that this is a net loss: You're adding hundreds of bytes of export symbol overhead, plus forcing gcc to emit actual calls at the call sites, with all the register saving/restoring that implies. Please just do this as static inlines. As I said, the linker is perfectly capable of merging string literals across translation units (but of course not between vmlinux and modules), so any built-in code that uses those helpers (or open-codes them, doesn't matter) will automatically share those literals. Rasmus