[PATCH] D67000: Fixes bug 28780

Shreyansh Chouhan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 30 06:05:54 PDT 2019


BK1603 updated this revision to Diff 218077.
BK1603 retitled this revision from "Fixes bug 28780 " to "Fixes bug 28780".
BK1603 added a comment.



1. Updating D67000 <https://reviews.llvm.org/D67000>: Fixes bug 28780 #
2. Enter a brief description of the changes included in this update.
3. The first line is used as subject, next lines as comment. #
4. If you intended to create a new revision, use:
5. $ arc diff --create

Added comment to the the code


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67000

Files:
  llvm/include/llvm/ADT/edit_distance.h
  llvm/unittests/ADT/StringRefTest.cpp


Index: llvm/unittests/ADT/StringRefTest.cpp
===================================================================
--- llvm/unittests/ADT/StringRefTest.cpp
+++ llvm/unittests/ADT/StringRefTest.cpp
@@ -508,6 +508,11 @@
 }
 
 TEST(StringRefTest, EditDistance) {
+	StringRef StrNull;
+	StringRef StrEmpty("");
+
+	EXPECT_EQ(0U, StrNull.edit_distance(""));
+	EXPECT_EQ(0U, StrEmpty.edit_distance(""));
   StringRef Hello("hello");
   EXPECT_EQ(2U, Hello.edit_distance("hill"));
 
Index: llvm/include/llvm/ADT/edit_distance.h
===================================================================
--- llvm/include/llvm/ADT/edit_distance.h
+++ llvm/include/llvm/ADT/edit_distance.h
@@ -57,6 +57,10 @@
   typename ArrayRef<T>::size_type m = FromArray.size();
   typename ArrayRef<T>::size_type n = ToArray.size();
 
+	// if either of the strings are empty, return the length of the other string.
+	if(m == 0) return n;
+	if(n == 0) return m;
+
   const unsigned SmallBufferSize = 64;
   unsigned SmallBuffer[SmallBufferSize];
   std::unique_ptr<unsigned[]> Allocated;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D67000.218077.patch
Type: text/x-patch
Size: 1055 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190830/8808c47d/attachment.bin>


More information about the llvm-commits mailing list