[llvm-commits] [llvm] r92884 - /llvm/trunk/lib/Support/StringRef.cpp
Douglas Gregor
dgregor at apple.com
Wed Jan 6 16:51:54 PST 2010
Author: dgregor
Date: Wed Jan 6 18:51:54 2010
New Revision: 92884
URL: http://llvm.org/viewvc/llvm-project?rev=92884&view=rev
Log:
Switch StringRef::edit_distance over to using raw pointers, since both
std::vector and llvm::SmallVector have annoying performance
tradeoffs. No, I don't expect this to matter, and now it won't.
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=92884&r1=92883&r2=92884&view=diff
==============================================================================
--- llvm/trunk/lib/Support/StringRef.cpp (original)
+++ llvm/trunk/lib/Support/StringRef.cpp Wed Jan 6 18:51:54 2010
@@ -8,7 +8,8 @@
//===----------------------------------------------------------------------===//
#include "llvm/ADT/StringRef.h"
-#include "llvm/ADT/SmallVector.h"
+#include <cstring>
+
using namespace llvm;
// MSVC emits references to this into the translation units which reference it.
@@ -51,13 +52,21 @@
size_type m = size();
size_type n = Other.size();
- SmallVector<unsigned, 32> previous(n+1, 0);
- for (SmallVector<unsigned, 32>::size_type i = 0; i <= n; ++i)
+ 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];
+ }
+
+ for (unsigned i = 0; i <= n; ++i)
previous[i] = i;
- SmallVector<unsigned, 32> current(n+1, 0);
for (size_type y = 1; y <= m; ++y) {
- current.assign(n+1, 0);
+ std::memset(current, 0, (n + 1) * sizeof(unsigned));
current[0] = y;
for (size_type x = 1; x <= n; ++x) {
if (AllowReplacements) {
@@ -69,10 +78,19 @@
else current[x] = min(current[x-1], previous[x]) + 1;
}
}
- current.swap(previous);
+
+ unsigned *tmp = current;
+ current = previous;
+ previous = tmp;
}
- return previous[n];
+ unsigned Result = previous[n];
+ if (n + 1 > 32) {
+ delete [] previous;
+ delete [] current;
+ }
+
+ return Result;
}
//===----------------------------------------------------------------------===//
More information about the llvm-commits
mailing list