]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
Merge pull request #17088 from zmedico/interval_set_intersection_of_optimization
authorSage Weil <sage@newdream.net>
Sat, 2 Sep 2017 02:06:36 +0000 (21:06 -0500)
committerGitHub <noreply@github.com>
Sat, 2 Sep 2017 02:06:36 +0000 (21:06 -0500)
interval_set: optimize intersection_of

Reviewed-by: Kefu Chai <kchai@redhat.com>
1  2 
src/include/interval_set.h

index e05eacae41efacf6383731da8aa09706ea9e2bc8,8b309db8470ad45b89cc0098fa6a0bca9b510013..5578c1ccc5d5278d33700d72add2a0fd2095c382
@@@ -461,10 -515,32 +515,33 @@@ class interval_set 
      assert(&b != this);
      clear();
  
+     const interval_set *s, *l;
+     if (a.size() < b.size()) {
+       s = &a;
+       l = &b;
+     } else {
+       s = &b;
+       l = &a;
+     }
+     if (!s->size())
+       return;
+     /*
+      * Use the lower_bound algorithm for larger size ratios
+      * where it performs better, but not for smaller size
+      * ratios where sequential search performs better.
+      */
+     if (l->size() / s->size() >= 10) {
+       intersection_size_asym(*s, *l);
+       return;
+     }
      typename std::map<T,T>::const_iterator pa = a.m.begin();
      typename std::map<T,T>::const_iterator pb = b.m.begin();
 -    
 +    typename decltype(m)::iterator mi = m.begin();
 +
      while (pa != a.m.end() && pb != b.m.end()) {
        // passing?
        if (pa->first + pa->second <= pb->first)