Changeset 1204 for trunk/yat/classifier


Ignore:
Timestamp:
Mar 5, 2008, 3:26:08 PM (13 years ago)
Author:
Peter
Message:

Return by value from FeatureSelector?. Copying a Lookup is cheap, so no reason to return by reference and keep a collection of garbage

Location:
trunk/yat/classifier
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/yat/classifier/FeatureSelector.cc

    r1134 r1204  
    4141  FeatureSelector::~FeatureSelector()
    4242  {
    43     for (std::list<const MatrixLookup*>::iterator i=garbage_.begin();
    44          i!=garbage_.end(); ++i)
    45       delete *i;
    46     for (std::list<const MatrixLookupWeighted*>::iterator i=
    47            garbage_weighted_.begin(); i!=garbage_weighted_.end(); ++i)
    48       delete *i;
    4943  }
    5044
     
    5650
    5751
    58   const MatrixLookup& FeatureSelector::get(const MatrixLookup& matrix)
     52  const MatrixLookup FeatureSelector::get(const MatrixLookup& matrix)
    5953  {
    60     garbage_.push_back(new MatrixLookup(matrix,utility::Index(features_),true));
    61     return *garbage_.back();
     54    return MatrixLookup(matrix, features_,true);
    6255  }
    6356
    6457
    65   const MatrixLookupWeighted&
     58  const MatrixLookupWeighted
    6659  FeatureSelector::get(const MatrixLookupWeighted& matrix)
    6760  {
    68     garbage_weighted_.push_back(new MatrixLookupWeighted(matrix,
    69                                                          utility::Index(features_),
    70                                                          true));
    71     return *garbage_weighted_.back();
     61    return MatrixLookupWeighted(matrix, features_, true);
    7262  }
    7363
  • trunk/yat/classifier/FeatureSelector.h

    r1134 r1204  
    5757    /// @return MatrixLookup containing only selected features.
    5858    ///
    59     const MatrixLookup& get(const MatrixLookup& data);
     59    const MatrixLookup get(const MatrixLookup& data);
    6060
    6161    ///
    6262    /// @return MatrixLookupWeighted containing only selected features.
    6363    ///
    64     const MatrixLookupWeighted& get(const MatrixLookupWeighted& data);
     64    const MatrixLookupWeighted get(const MatrixLookupWeighted& data);
    6565
    6666    ///
     
    9797
    9898  private:
    99     std::list<const MatrixLookup*> garbage_;
    100     std::list<const MatrixLookupWeighted*> garbage_weighted_;
    10199
    102100  };
Note: See TracChangeset for help on using the changeset viewer.