[llvm] 3ab51ff - [llvm] Replace array allocation pattern by SmallVector in ComputeMappedEditDistance
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 25 22:59:51 PST 2023
Author: serge-sans-paille
Date: 2023-01-26T07:59:38+01:00
New Revision: 3ab51fff3c2a044196f4b4634fab8c29f87dd7ee
URL: https://github.com/llvm/llvm-project/commit/3ab51fff3c2a044196f4b4634fab8c29f87dd7ee
DIFF: https://github.com/llvm/llvm-project/commit/3ab51fff3c2a044196f4b4634fab8c29f87dd7ee.diff
LOG: [llvm] Replace array allocation pattern by SmallVector in ComputeMappedEditDistance
Differential Revision: https://reviews.llvm.org/D142574
Added:
Modified:
llvm/include/llvm/ADT/edit_distance.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/ADT/edit_distance.h b/llvm/include/llvm/ADT/edit_distance.h
index 6df3db6125d40..00387836c97e3 100644
--- a/llvm/include/llvm/ADT/edit_distance.h
+++ b/llvm/include/llvm/ADT/edit_distance.h
@@ -18,7 +18,6 @@
#include "llvm/ADT/ArrayRef.h"
#include <algorithm>
-#include <memory>
namespace llvm {
@@ -70,16 +69,8 @@ unsigned ComputeMappedEditDistance(ArrayRef<T> FromArray, ArrayRef<T> ToArray,
return MaxEditDistance + 1;
}
- const unsigned SmallBufferSize = 64;
- unsigned SmallBuffer[SmallBufferSize];
- std::unique_ptr<unsigned[]> Allocated;
- unsigned *Row = SmallBuffer;
- if (n + 1 > SmallBufferSize) {
- Row = new unsigned[n + 1];
- Allocated.reset(Row);
- }
-
- for (unsigned i = 1; i <= n; ++i)
+ SmallVector<unsigned, 64> Row(n + 1);
+ for (unsigned i = 1; i < Row.size(); ++i)
Row[i] = i;
for (typename ArrayRef<T>::size_type y = 1; y <= m; ++y) {
More information about the llvm-commits
mailing list