aboutsummaryrefslogtreecommitdiff
path: root/lib/Support/StringRef.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Support/StringRef.cpp')
-rw-r--r--lib/Support/StringRef.cpp11
1 files changed, 6 insertions, 5 deletions
diff --git a/lib/Support/StringRef.cpp b/lib/Support/StringRef.cpp
index 5ad862815b..d5fd12727d 100644
--- a/lib/Support/StringRef.cpp
+++ b/lib/Support/StringRef.cpp
@@ -9,6 +9,7 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/APInt.h"
+#include "llvm/ADT/OwningPtr.h"
#include <bitset>
using namespace llvm;
@@ -84,10 +85,12 @@ unsigned StringRef::edit_distance(llvm::StringRef Other,
const unsigned SmallBufferSize = 64;
unsigned SmallBuffer[SmallBufferSize];
- unsigned *Allocated = 0;
+ llvm::OwningArrayPtr<unsigned> Allocated;
unsigned *previous = SmallBuffer;
- if (2*(n + 1) > SmallBufferSize)
- Allocated = previous = new unsigned [2*(n+1)];
+ if (2*(n + 1) > SmallBufferSize) {
+ previous = new unsigned [2*(n+1)];
+ Allocated.reset(previous);
+ }
unsigned *current = previous + (n + 1);
for (unsigned i = 0; i <= n; ++i)
@@ -118,8 +121,6 @@ unsigned StringRef::edit_distance(llvm::StringRef Other,
}
unsigned Result = previous[n];
- delete [] Allocated;
-
return Result;
}