std::vector and llvm::SmallVector have annoying performance
tradeoffs. No, I don't expect this to matter, and now it won't.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@92884
91177308-0d34-0410-b5e6-
96231b3b80d8
//===----------------------------------------------------------------------===//
#include "llvm/ADT/StringRef.h"
//===----------------------------------------------------------------------===//
#include "llvm/ADT/StringRef.h"
-#include "llvm/ADT/SmallVector.h"
using namespace llvm;
// MSVC emits references to this into the translation units which reference it.
using namespace llvm;
// MSVC emits references to this into the translation units which reference it.
size_type m = size();
size_type n = Other.size();
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)
- SmallVector<unsigned, 32> current(n+1, 0);
for (size_type y = 1; y <= m; ++y) {
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) {
current[0] = y;
for (size_type x = 1; x <= n; ++x) {
if (AllowReplacements) {
else current[x] = min(current[x-1], previous[x]) + 1;
}
}
else current[x] = min(current[x-1], previous[x]) + 1;
}
}
- current.swap(previous);
+
+ unsigned *tmp = current;
+ current = previous;
+ previous = tmp;
+ unsigned Result = previous[n];
+ if (n + 1 > 32) {
+ delete [] previous;
+ delete [] current;
+ }
+
+ return Result;
}
//===----------------------------------------------------------------------===//
}
//===----------------------------------------------------------------------===//