OSDN Git Service

ART: Nano optimization of LiveInterval
authorDavid Brazdil <dbrazdil@google.com>
Wed, 25 Feb 2015 11:57:05 +0000 (11:57 +0000)
committerDavid Brazdil <dbrazdil@google.com>
Wed, 25 Feb 2015 11:57:05 +0000 (11:57 +0000)
Shuffling the order of conditions in the FirstIntersectionWith method
of LiveInterval class can save a couple of comparisons. Even though
this is a tiny optimization, it can save some compilation time since
the method is heavily used during register allocation.

Change-Id: I1817bd95db2d0eb96cc06fb2e9e06ac1cea784fe

compiler/optimizing/ssa_liveness_analysis.h

index be72629..45b433f 100644 (file)
@@ -345,19 +345,19 @@ class LiveInterval : public ArenaObject<kArenaAllocMisc> {
     LiveRange* my_range = first_range_;
     LiveRange* other_range = other->first_range_;
     do {
-      if (my_range->IntersectsWith(*other_range)) {
-        return std::max(my_range->GetStart(), other_range->GetStart());
-      } else if (my_range->IsBefore(*other_range)) {
+      if (my_range->IsBefore(*other_range)) {
         my_range = my_range->GetNext();
         if (my_range == nullptr) {
           return kNoLifetime;
         }
-      } else {
-        DCHECK(other_range->IsBefore(*my_range));
+      } else if (other_range->IsBefore(*my_range)) {
         other_range = other_range->GetNext();
         if (other_range == nullptr) {
           return kNoLifetime;
         }
+      } else {
+        DCHECK(my_range->IntersectsWith(*other_range));
+        return std::max(my_range->GetStart(), other_range->GetStart());
       }
     } while (true);
   }