[PATCH] D142574: [llvm] Replace array allocation pattern by SmallVector in ComputeMappedEditDistance

serge via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 25 13:36:48 PST 2023


serge-sans-paille updated this revision to Diff 492244.
serge-sans-paille added a comment.

I did a quick check and it was indeed tuned


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142574/new/

https://reviews.llvm.org/D142574

Files:
  llvm/include/llvm/ADT/edit_distance.h


Index: llvm/include/llvm/ADT/edit_distance.h
===================================================================
--- llvm/include/llvm/ADT/edit_distance.h
+++ 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 @@
       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) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142574.492244.patch
Type: text/x-patch
Size: 833 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230125/f562c5d4/attachment.bin>


More information about the llvm-commits mailing list