Lichen

Changeset

893:a13fc2cc28f0
2019-02-04 Paul Boddie raw files shortlog changelog graph Optimised __BOOL to test for integers and to return int values directly. For other value types, __VALUE need not be called once integers have been excluded, and so the attrvalue member can be accessed directly.
templates/progops.c (file)
     1.1 --- a/templates/progops.c	Sat Feb 02 17:54:22 2019 +0100
     1.2 +++ b/templates/progops.c	Mon Feb 04 18:30:28 2019 +0100
     1.3 @@ -304,9 +304,17 @@
     1.4  
     1.5  int __BOOL(__attr attr)
     1.6  {
     1.7 -    /* Invoke the bool function with the object and test against True. */
     1.8 +    __ref value;
     1.9 +
    1.10 +    /* Integers can be used directly as truth values. */
    1.11  
    1.12 -    __ref value = __VALUE(attr);
    1.13 +    if (__INTEGER(attr))
    1.14 +        return __TOINT(attr);
    1.15 +
    1.16 +    /* Test against True and False explicitly. If necessary, invoke the bool
    1.17 +       function with the object and test against True. */
    1.18 +
    1.19 +    value = attr.value;
    1.20  
    1.21      return value == &__predefined___builtins___boolean_True ? 1 :
    1.22             value == &__predefined___builtins___boolean_False ? 0 :