[llvm-commits] [llvm] r120265 - /llvm/trunk/include/llvm/ADT/IntervalMap.h

Jakob Stoklund Olesen stoklund at 2pi.dk
Sun Nov 28 14:17:14 PST 2010


Author: stoklund
Date: Sun Nov 28 16:17:14 2010
New Revision: 120265

URL: http://llvm.org/viewvc/llvm-project?rev=120265&view=rev
Log:
Don't use std::copy and std::copy_backward, run 10% faster.

Sometimes std::copy can become a memmove call, and that is not a good idea when
copying relatively few bytes as we are doing. We also get a small win by
changing two loops into one.

Modified:
    llvm/trunk/include/llvm/ADT/IntervalMap.h

Modified: llvm/trunk/include/llvm/ADT/IntervalMap.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/IntervalMap.h?rev=120265&r1=120264&r2=120265&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/IntervalMap.h (original)
+++ llvm/trunk/include/llvm/ADT/IntervalMap.h Sun Nov 28 16:17:14 2010
@@ -103,7 +103,6 @@
 #include "llvm/ADT/PointerIntPair.h"
 #include "llvm/Support/Allocator.h"
 #include "llvm/Support/RecyclingAllocator.h"
-#include <limits>
 #include <iterator>
 
 // FIXME: Remove debugging code.
@@ -211,8 +210,10 @@
             unsigned j, unsigned Count) {
     assert(i + Count <= M && "Invalid source range");
     assert(j + Count <= N && "Invalid dest range");
-    std::copy(Other.first + i, Other.first + i + Count, first + j);
-    std::copy(Other.second + i, Other.second + i + Count, second + j);
+    for (unsigned e = i + Count; i != e; ++i, ++j) {
+      first[j]  = Other.first[i];
+      second[j] = Other.second[i];
+    }
   }
 
   /// moveLeft - Move elements to the left.
@@ -231,8 +232,10 @@
   void moveRight(unsigned i, unsigned j, unsigned Count) {
     assert(i <= j && "Use moveLeft shift elements left");
     assert(j + Count <= N && "Invalid range");
-    std::copy_backward(first + i, first + i + Count, first + j + Count);
-    std::copy_backward(second + i, second + i + Count, second + j + Count);
+    while (Count--) {
+      first[j + Count]  = first[i + Count];
+      second[j + Count] = second[i + Count];
+    }
   }
 
   /// erase - Erase elements [i;j).





More information about the llvm-commits mailing list