All of lore.kernel.org
 help / color / mirror / Atom feed
* [KJ] [RFC] A need for a "yesno"-function?
@ 2007-03-15 14:08 Richard Knutsson
  2007-03-16  3:36 ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 14+ messages in thread
From: Richard Knutsson @ 2007-03-15 14:08 UTC (permalink / raw)
  To: kernel-janitors

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?

Richard Knutsson

_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
https://lists.osdl.org/mailman/listinfo/kernel-janitors

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2007-03-17  1:02 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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   ` [KJ] [RFC] A need for "yesno"-function? (and "cleanup" of kernel.h) Richard Knutsson
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

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.