cogent icon indicating copy to clipboard operation
cogent copied to clipboard

&& and || should shortcut

Open zilinc opened this issue 8 years ago • 1 comments

Issue by chu090 Wed Dec 9 08:58:51 2015 Originally opened as https://github.csiro.au/ts-filesystems/Cogent/issues/110


We're doing more work than necessary. For instance, in ext2_match, the code is dirent.inode /= 0 && wordarray_cmp (c_name, dirent.name)

If dirent.inode is zero there's no need to call the external comparison function.

zilinc avatar Dec 01 '17 23:12 zilinc

Comment by lim060 Wed Dec 9 09:51:11 2015


We can't always translate this to the desired && in C, because the right operand could (and in this case, will) generate multiple statements. The simplest solution now is to just implement the short-circuiting manually:

if dirent.inode /= 0 then wordarray_cmp(c_name, dirent.name) else False

(The ANF compiler pass then blows it up, but that's another issue.)

zilinc avatar Dec 01 '17 23:12 zilinc