Changeset 756 for trunk/lib


Ignore:
Timestamp:
Jan 27, 2009, 12:13:28 AM (13 years ago)
Author:
Peter Johansson
Message:

refs #74 - using stl rather than home brewed in SVNlog::operator+=

Location:
trunk/lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Commitment.h

    r693 r756  
    9191  };
    9292
     93  struct LessRevision
     94  {
     95    inline bool operator()(const Commitment& lhs, const Commitment& rhs)
     96    { return lhs.revision()<rhs.revision(); }
     97  };
     98
    9399}} // end of namespace svndigest and namespace theplu
    94100
  • trunk/lib/SVNlog.cc

    r693 r756  
    114114  {
    115115    SVNlog log;
    116     std::vector<Commitment>::iterator lhs_iter=lhs.commits().begin();
    117     std::vector<Commitment>::const_iterator rhs_iter=rhs.commits().begin();
    118     while(lhs_iter<lhs.commits().end() && rhs_iter<rhs.commits().end()) {
    119       if (lhs_iter->revision() < rhs_iter->revision()) {
    120        
    121         log.commits().push_back(*lhs_iter);
    122         ++lhs_iter;
    123       }
    124       else if (rhs_iter->revision()<lhs_iter->revision()) {
    125         log.commits().push_back(*rhs_iter);
    126         ++rhs_iter;
    127       }
    128       else {
    129         log.commits().push_back(*lhs_iter);
    130         ++lhs_iter;
    131         ++rhs_iter;
    132       }
    133     }
    134     while(lhs_iter<lhs.commits().end()) {
    135       log.commits().push_back(*lhs_iter);
    136       ++lhs_iter;
    137     }
    138     while(rhs_iter<rhs.commits().end()) {
    139       log.commits().push_back(*rhs_iter);
    140       ++rhs_iter;
    141     }
     116    log.commits().reserve(std::max(lhs.commits().size(), rhs.commits().size()));
     117    std::set_union(lhs.commits().begin(), lhs.commits().end(),
     118                   rhs.commits().begin(), rhs.commits().end(),
     119                   std::back_inserter(log.commits()), LessRevision());
    142120    lhs.swap(log);
    143121    return lhs;
Note: See TracChangeset for help on using the changeset viewer.