summaryrefslogtreecommitdiff
path: root/lib/Support
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-01-07 02:24:06 +0000
committerDouglas Gregor <dgregor@apple.com>2010-01-07 02:24:06 +0000
commit2772ea831cc7ba6f6016b93f8dea143607013094 (patch)
treeae09e86e8296460bd5c7fae995bd718208682aa8 /lib/Support
parent4039bd055086ec741132afe32f1ab7fdf5ebd710 (diff)
downloadllvm-2772ea831cc7ba6f6016b93f8dea143607013094.tar.gz
llvm-2772ea831cc7ba6f6016b93f8dea143607013094.tar.bz2
llvm-2772ea831cc7ba6f6016b93f8dea143607013094.tar.xz
More trivial optimizations to a function well outside the critical path
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@92896 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support')
-rw-r--r--lib/Support/StringRef.cpp23
1 files changed, 8 insertions, 15 deletions
diff --git a/lib/Support/StringRef.cpp b/lib/Support/StringRef.cpp
index e577b954c5..ae2640b5b9 100644
--- a/lib/Support/StringRef.cpp
+++ b/lib/Support/StringRef.cpp
@@ -8,7 +8,6 @@
//===----------------------------------------------------------------------===//
#include "llvm/ADT/StringRef.h"
-#include <cstring>
using namespace llvm;
@@ -52,21 +51,18 @@ unsigned StringRef::edit_distance(llvm::StringRef Other,
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 StringRef::edit_distance(llvm::StringRef Other,
}
unsigned Result = previous[n];
- if (n + 1 > 32) {
- delete [] previous;
- delete [] current;
- }
+ delete [] Allocated;
return Result;
}