All of lore.kernel.org
 help / color / mirror / Atom feed
From: "David Dabbs" <david@dabbs.net>
To: 'Nikita Danilov' <Nikita@Clusterfs.COM>
Cc: reiserfs-list@namesys.com
Subject: RE: Performance improvements to key comparison functions
Date: Mon, 12 Jul 2004 15:26:27 -0500	[thread overview]
Message-ID: <20040712202654.C757F16096@mail03.powweb.com> (raw)
In-Reply-To: <16626.61112.905268.684688@laputa.namesys.com>


Thanks for looking over the code and for your responses.

> Nikita wrote
> Note that comparisons in C (like (v1 > v2)) are not guaranteed to return 0
> or _1_ as a result, but simply zero, or _non-zero_.

Is the information here (http://www.lysator.liu.se/c/c-faq/c-8.html)
incorrect then? Specifically,

---8<  snip

It is true (sic) that any nonzero value is considered true in C, but this
applies only "on input", i.e. where a boolean value is expected.  When a
boolean value is generated by a built-in operator, it is guaranteed to be 1
or 0.  Therefore, the test 


	if((a == b) == TRUE)

will work as expected (as long as TRUE is 1), but it is obviously silly.  In
general, explicit tests against TRUE and FALSE are undesirable, because some
library functions (notably isupper, isalpha, etc.) return, on success, a
nonzero value which is not necessarily 1.  (Besides, if you believe that
"if((a == b) == TRUE)" is an improvement over "if(a == b)", why stop there?
Why not use "if(((a == b) == TRUE) == TRUE)"?)  A good rule of thumb is to
use TRUE and FALSE (or the like) only for assignment to a Boolean variable
or function parameter, or as the return value from a Boolean function, but
never in a comparison. 

The preprocessor macros TRUE and FALSE are used for code readability, not
because the underlying values might ever change.  (See also questions 1.7
and 1.9.) 

References: K&R I Sec. 2.7 p. 41; K&R II Sec. 2.6 p. 42, Sec. A7.4.7 p. 204,
Sec. A7.9 p. 206; ANSI Secs. 3.3.3.3, 3.3.8, 3.3.9, 3.3.13, 3.3.14, 3.3.15,
3.6.4.1, 3.6.5; Achilles and the Tortoise. 

---8<  snip


> In the same vein, "isunique" argument of
> znode_contains_key_strict_new() is not guaranteed to be 0 or 1
> which renders this function wrong.
> That said, I think that proper way to test your functions is to plug
> them into kernel reiser4 version and run some CPU intensive tests.

I thought I noted in "System Impacts" that when isunique is initialized by
ORing the flag that the initialization expression must change to be a
Boolean result of the OR test. Something like 

	isunique = ((h->flags & CBK_UNIQUE) == CBK_UNIQUE);

That may have not made it in.
 
As to testing in the kernel, I completely agree. Before going there I
thought I'd get community feedback to see whether there was something subtle
I had missed.

Thanks again,

David



  reply	other threads:[~2004-07-12 20:26 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-07-12 18:38 Performance improvements to key comparison functions David Dabbs
2004-07-12 20:04 ` Nikita Danilov
2004-07-12 20:26   ` David Dabbs [this message]
2004-07-10 23:18     ` Nikita Danilov
2004-07-12 21:27       ` David Dabbs
2004-07-11  0:01         ` Nikita Danilov
2004-07-12 22:03           ` David Dabbs
2004-07-12 12:00             ` Nikita Danilov
2004-07-13 17:58               ` David Dabbs
2004-07-12 20:49   ` David Dabbs
2004-07-10 23:23     ` Nikita Danilov
2004-07-12 21:07     ` mjt
2004-07-13 18:19       ` Hans Reiser
2004-07-12 21:42     ` Philippe Gramoullé
  -- strict thread matches above, loose matches on Subject: below --
2004-07-12  8:48 David Dabbs
2004-07-13 18:33 ` Hans Reiser
2004-07-13 19:59   ` David Dabbs
2004-07-14  6:59     ` Hans Reiser
2004-06-22 10:53       ` David Dabbs
2004-07-13 22:18   ` David Dabbs
2004-07-14  7:03     ` Hans Reiser
2004-06-23  8:43 David Dabbs

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=20040712202654.C757F16096@mail03.powweb.com \
    --to=david@dabbs.net \
    --cc=Nikita@Clusterfs.COM \
    --cc=reiserfs-list@namesys.com \
    /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.