[llvm-commits] [llvm] r92896 - /llvm/trunk/lib/Support/StringRef.cpp

Douglas Gregor dgregor at apple.com
Wed Jan 6 18:24:07 PST 2010


Author: dgregor
Date: Wed Jan  6 20:24:06 2010
New Revision: 92896

URL: http://llvm.org/viewvc/llvm-project?rev=92896&view=rev
Log:
More trivial optimizations to a function well outside the critical path

Modified:
    llvm/trunk/lib/Support/StringRef.cpp

Modified: llvm/trunk/lib/Support/StringRef.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/StringRef.cpp?rev=92896&r1=92895&r2=92896&view=diff

==============================================================================
--- llvm/trunk/lib/Support/StringRef.cpp (original)
+++ llvm/trunk/lib/Support/StringRef.cpp Wed Jan  6 20:24:06 2010
@@ -8,7 +8,6 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/ADT/StringRef.h"
-#include <cstring>
 
 using namespace llvm;
 
@@ -52,21 +51,18 @@
   size_type m = size();
   size_type n = Other.size();
 
-  unsigned SmallPrevious[32];
-  unsigned SmallCurrent[32];
-  
-  unsigned *previous = SmallPrevious;
-  unsigned *current = SmallCurrent;
-  if (n + 1 > 32) {
-    previous = new unsigned [n+1];
-    current = new unsigned [n+1];
-  }
+  const unsigned SmallBufferSize = 64;
+  unsigned SmallBuffer[SmallBufferSize];
+  unsigned *Allocated = 0;
+  unsigned *previous = SmallBuffer;
+  if (2*(n + 1) > SmallBufferSize)
+    Allocated = previous = new unsigned [2*(n+1)];
+  unsigned *current = previous + (n + 1);
   
   for (unsigned i = 0; i <= n; ++i) 
     previous[i] = i;
 
   for (size_type y = 1; y <= m; ++y) {
-    std::memset(current, 0, (n + 1) * sizeof(unsigned));
     current[0] = y;
     for (size_type x = 1; x <= n; ++x) {
       if (AllowReplacements) {
@@ -85,10 +81,7 @@
   }
 
   unsigned Result = previous[n];
-  if (n + 1 > 32) {
-    delete [] previous;
-    delete [] current;
-  }
+  delete [] Allocated;
   
   return Result;
 }





More information about the llvm-commits mailing list