View Issue Details

IDProjectCategoryView StatusLast Update
0029749RunnerWindows (YYC)Public2019-05-13 17:16
ReporterYellowAfterlifeAssigned ToRussell Kay 
PriorityLowSeverityC - GeneralReproducibility100%
Status ClosedResolutionFixed 
PlatformWindowsOSWindows 10 ProOS Version>=1703
Product Version2.1.4 
Target Version2.2.1Fixed in Version2.2.1 
Summary0029749: Windows (YYC): ternary operator does a cast (copy, discard) to YYRValue even though it doesn't need to
Description
if (argument_count > 0) v = argument[0]; else v = 0;

becomes
if((argc > 0)) {
local_v=(*_args[(int)(0)]);
}
else {
local_v=0;
}

while
v = argument_count > 0 ? argument[0] : 0

becomes
local_v=((argc > 0) ? YYRValue((*_args[(int)(0)])) : YYRValue(0));


YYRValue constructor is
	YYRValue( const YYRValue& _v ) {
        __localCopy( _v );
    } // end YYRValue

and assignment operator is
	YYRValue& operator=( const YYRValue& _v ) {
        if (&_v != this) {
            __localFree();
            __localCopy( _v );
        } // end if
        return *this;
    } // end operator=

and destructor is
	~YYRValue() {
        __localFree();
        //FREE_RValue__Pre( this );
    } // end YYRValue

so the ternary operator makes a new YYRvalue, copies the desired value to it, copies the value from it to destination, and throws it away, while doing an if-then-else just copies the value straight to the destination.
Additional InformationThis results in ternary operator being a little (1.2x if assigning an YYRValue containing a primitive type) or not so little (if assigning constants or not-so-little (3x if assigning constants) slower than an if-then-else branch.
TagsNo tags attached.
1.4 Found In
2.x Runtime Found In9.9.1.1074
2.x Runtime Verified In9.9.1.1437

Activities

YellowAfterlife

2018-07-04 12:56

Developer  

a_bug.yyz (46,280 bytes)

Russell Kay

2018-07-17 21:24

Manager   ~0060880

Fixed in gitlab at least as much as I can, more of an improvement.

One of the limitations of the Ternary operator (in C++) is that both sides have to return the same type, the lowest common denominator is YYRValue at the moment we always return that, but we were casting it all the time rather than recognising that any of them were already an YYRValue so I have changed it to recognise this and only casts if it needs to.