[llvm] Replace array allocation pattern by SmallVector in ComputeMappedEditDistance
authorserge-sans-paille <sguelton@mozilla.com>
Wed, 25 Jan 2023 19:43:06 +0000 (20:43 +0100)
committerserge-sans-paille <sguelton@mozilla.com>
Thu, 26 Jan 2023 06:59:38 +0000 (07:59 +0100)
Differential Revision: https://reviews.llvm.org/D142574

llvm/include/llvm/ADT/edit_distance.h

index 6df3db6..0038783 100644 (file)
@@ -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) {