From: Richard Knutsson <ricknu-0@student.ltu.se>
To: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Cc: Kernel Janitors List <kernel-janitors@lists.osdl.org>,
linux-kernel@vger.kernel.org
Subject: [KJ] [RFC] A need for "yesno"-function? (and "cleanup" of kernel.h)
Date: Fri, 16 Mar 2007 15:24:53 +0000 [thread overview]
Message-ID: <45FAB6C5.8050302@student.ltu.se> (raw)
In-Reply-To: <39e6f6c70703152036m778ea054gf32723d0eda2be68@mail.gmail.com>
Added LKML to the Cc: to see if there is someone there who also have any
comments...
Arnaldo Carvalho de Melo wrote:
> On 3/15/07, Richard Knutsson <ricknu-0@student.ltu.se> wrote:
>> Hi
>>
>> Was just checking up the 'sparse' when I saw something like "abc"[value]
>> and thought: what about the (statement) ? "yes" : "no" I have seen in
>> the kernel.
>>
>> Ran:
>> grep -Enr "\?.*y.*\:.*n" *
>> and to my surprise, it was not so false-positive-prone and there are
>> many who does it. (Piping it to "grep yes" resulted in 153 hits) So I
>> thought, if we could standardize this and eliminate some jmp-commands
>> while doing it (the compiler should make the functions below inline), it
>> might be interesting.
>>
>> char yesno_chr(const bool value)
>> {
>> return "ny"[value];
>> }
>>
>> char *yesno_str(const bool value)
>> {
>> return &"no\0yes"[3 * value];
>> }
>>
>>
>> (there may be better names for them)
>> I believe this should be slightly faster. I wrote two programs (one for
>> each approach) and used 'time' while running them, and in a loop of
>> 1000,000 I found the above to be slightly faster, but the variations
>> between runs were larger.
>> So maybe it is as well to write: return value ? "yes" : "no"; but i
>> think there is a need for this kind of functions at least.
>>
>> Thoughts?
>
> The function makes sense, how you implement it? Something simple as
> this is hardly on a fast path 8)
True, but every cycled wasted... ;)
But a (condition) ? "yes" : "no" is preferable here, I guess (as it is
more readable). The big problem is, where to put it? Seems wrong to put
in <linux/string.h> since it appear to be a replica of userspace's
<string.h> (otherwise, why put mem*-functions in there?).
A new file? What would it be then, "string_generic.h" maybe, and perhaps
put in the pr_(info/debug), KERN_(WARN/...) and v?printk() (well, all
those functions) in there. This means it will have to be included by
<linux/kernel.h> but I think it would be a good thing to split out a few
functions from it.
Just putting some ideas out there, any suggestions?
Richard Knutsson
_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
https://lists.osdl.org/mailman/listinfo/kernel-janitors
WARNING: multiple messages have this Message-ID (diff)
From: Richard Knutsson <ricknu-0@student.ltu.se>
To: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Cc: Kernel Janitors List <kernel-janitors@lists.osdl.org>,
linux-kernel@vger.kernel.org
Subject: [RFC] A need for "yesno"-function? (and "cleanup" of kernel.h) (was: Re: [KJ] [RFC] A need for a "yesno"-function?)
Date: Fri, 16 Mar 2007 16:24:53 +0100 [thread overview]
Message-ID: <45FAB6C5.8050302@student.ltu.se> (raw)
In-Reply-To: <39e6f6c70703152036m778ea054gf32723d0eda2be68@mail.gmail.com>
Added LKML to the Cc: to see if there is someone there who also have any
comments...
Arnaldo Carvalho de Melo wrote:
> On 3/15/07, Richard Knutsson <ricknu-0@student.ltu.se> wrote:
>> Hi
>>
>> Was just checking up the 'sparse' when I saw something like "abc"[value]
>> and thought: what about the (statement) ? "yes" : "no" I have seen in
>> the kernel.
>>
>> Ran:
>> grep -Enr "\?.*y.*\:.*n" *
>> and to my surprise, it was not so false-positive-prone and there are
>> many who does it. (Piping it to "grep yes" resulted in 153 hits) So I
>> thought, if we could standardize this and eliminate some jmp-commands
>> while doing it (the compiler should make the functions below inline), it
>> might be interesting.
>>
>> char yesno_chr(const bool value)
>> {
>> return "ny"[value];
>> }
>>
>> char *yesno_str(const bool value)
>> {
>> return &"no\0yes"[3 * value];
>> }
>>
>>
>> (there may be better names for them)
>> I believe this should be slightly faster. I wrote two programs (one for
>> each approach) and used 'time' while running them, and in a loop of
>> 1000,000 I found the above to be slightly faster, but the variations
>> between runs were larger.
>> So maybe it is as well to write: return value ? "yes" : "no"; but i
>> think there is a need for this kind of functions at least.
>>
>> Thoughts?
>
> The function makes sense, how you implement it? Something simple as
> this is hardly on a fast path 8)
True, but every cycled wasted... ;)
But a (condition) ? "yes" : "no" is preferable here, I guess (as it is
more readable). The big problem is, where to put it? Seems wrong to put
in <linux/string.h> since it appear to be a replica of userspace's
<string.h> (otherwise, why put mem*-functions in there?).
A new file? What would it be then, "string_generic.h" maybe, and perhaps
put in the pr_(info/debug), KERN_(WARN/...) and v?printk() (well, all
those functions) in there. This means it will have to be included by
<linux/kernel.h> but I think it would be a good thing to split out a few
functions from it.
Just putting some ideas out there, any suggestions?
Richard Knutsson
next prev parent reply other threads:[~2007-03-16 15:24 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-03-15 14:08 [KJ] [RFC] A need for a "yesno"-function? Richard Knutsson
2007-03-16 3:36 ` Arnaldo Carvalho de Melo
2007-03-16 15:24 ` Richard Knutsson [this message]
2007-03-16 15:24 ` [RFC] A need for "yesno"-function? (and "cleanup" of kernel.h) (was: Re: [KJ] [RFC] A need for a "yesno"-function?) Richard Knutsson
2007-03-16 16:33 ` [KJ] [RFC] A need for "yesno"-function? (and "cleanup" of Bernd Petrovitsch
2007-03-16 16:33 ` [RFC] A need for "yesno"-function? (and "cleanup" of kernel.h) (was: Re: [KJ] [RFC] A need for a "yesno"-function?) Bernd Petrovitsch
2007-03-16 17:09 ` [KJ] [RFC] A need for "yesno"-function? (and "cleanup" of Richard Knutsson
2007-03-16 17:09 ` [RFC] A need for "yesno"-function? (and "cleanup" of kernel.h) (was: Re: [KJ] [RFC] A need for a "yesno"-function?) Richard Knutsson
2007-03-16 17:15 ` [KJ] [RFC] A need for "yesno"-function? (and "cleanup" of Bernd Petrovitsch
2007-03-16 17:15 ` [RFC] A need for "yesno"-function? (and "cleanup" of kernel.h) Bernd Petrovitsch
2007-03-16 23:20 ` [KJ] [RFC] A need for "yesno"-function? (and "cleanup" of Jan Engelhardt
2007-03-16 23:20 ` [RFC] A need for "yesno"-function? (and "cleanup" of kernel.h) (was: Re: [KJ] [RFC] A need for a "yesno"-function?) Jan Engelhardt
2007-03-17 0:59 ` [KJ] [RFC] A need for "yesno"-function? (and "cleanup" of Richard Knutsson
2007-03-17 0:59 ` [RFC] A need for "yesno"-function? (and "cleanup" of kernel.h) Richard Knutsson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=45FAB6C5.8050302@student.ltu.se \
--to=ricknu-0@student.ltu.se \
--cc=acme@ghostprotocols.net \
--cc=kernel-janitors@lists.osdl.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.