Ignore:
Timestamp:
Jul 17, 2017, 2:35:52 PM (7 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
7ebaa56
Parents:
b46e3bd
Message:

Remove Cost constructors, use only named members

This change makes it easier to read code involving costs, since in almost every case, only a single part of the cost tuple is relevant. Furthermore, this change makes it much simpler to add another dimension to the cost tuple, since only Cost.h needs to be updated, rather than every location using the cost constructor.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/Cost.h

    rb46e3bd r89be1c68  
    2121namespace ResolvExpr {
    2222        class Cost {
    23           public:
    24                 Cost();
     23          private:
    2524                Cost( int unsafeCost, int polyCost, int safeCost );
    2625
    27                 void incUnsafe( int inc = 1 );
    28                 void incPoly( int inc = 1 );
    29                 void incSafe( int inc = 1 );
     26          public:
     27                Cost & incUnsafe( int inc = 1 );
     28                Cost & incPoly( int inc = 1 );
     29                Cost & incSafe( int inc = 1 );
    3030
    3131                Cost operator+( const Cost &other ) const;
     
    5050        };
    5151
    52         inline Cost::Cost() : unsafeCost( 0 ), polyCost( 0 ), safeCost( 0 ) {}
    53 
    5452        inline Cost::Cost( int unsafeCost, int polyCost, int safeCost ) : unsafeCost( unsafeCost ), polyCost( polyCost ), safeCost( safeCost ) {}
    5553
    56         inline void Cost::incUnsafe( int inc ) {
     54        inline Cost & Cost::incUnsafe( int inc ) {
    5755                unsafeCost += inc;
     56                return *this;
    5857        }
    5958
    60         inline void Cost::incPoly( int inc ) {
     59        inline Cost & Cost::incPoly( int inc ) {
    6160                polyCost += inc;
     61                return *this;
    6262        }
    6363
    64         inline void Cost::incSafe( int inc ) {
     64        inline Cost & Cost::incSafe( int inc ) {
    6565                safeCost += inc;
     66                return *this;
    6667        }
    6768
Note: See TracChangeset for help on using the changeset viewer.