Skip to content

Commit 667a145

Browse files
committed
simplify
1 parent a6c0bc1 commit 667a145

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

stringdiff/src/main/scala/app/tulz/diff/util/DiffTokenize.scala

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ private[diff] object DiffTokenize {
4444
.takeWhile(i =>
4545
i <= group2.size &&
4646
((group1(i - 1), group2(i - 1)) match {
47-
case (InFirst(first), InSecond(second)) => same(first, second)
48-
case (InSecond(second), InFirst(first)) => same(first, second)
47+
case (InFirst(first), InSecond(second)) => first == second
48+
case (InSecond(second), InFirst(first)) => first == second
4949
case _ => false
5050
})
5151
).lastOption.map { samePrefixLength =>
@@ -72,8 +72,8 @@ private[diff] object DiffTokenize {
7272
.takeWhile(i =>
7373
i <= group2.size &&
7474
((group1(group1.length - i), group2(group2.size - i)) match {
75-
case (InFirst(first), InSecond(second)) => same(first, second)
76-
case (InSecond(second), InFirst(first)) => same(first, second)
75+
case (InFirst(first), InSecond(second)) => first == second
76+
case (InSecond(second), InFirst(first)) => first == second
7777
case _ => false
7878
})
7979
).lastOption.map { sameSuffixLength =>
@@ -100,8 +100,8 @@ private[diff] object DiffTokenize {
100100
.takeWhile(i =>
101101
i <= group2.size &&
102102
group1.take(i).zip(group2.takeRight(i)).forall {
103-
case (InFirst(first), InSecond(second)) => same(first, second)
104-
case (InSecond(second), InFirst(first)) => same(first, second)
103+
case (InFirst(first), InSecond(second)) => first == second
104+
case (InSecond(second), InFirst(first)) => first == second
105105
case _ => false
106106
}
107107
).lastOption.map { prefixSuffixLength =>
@@ -128,8 +128,8 @@ private[diff] object DiffTokenize {
128128
.takeWhile(i =>
129129
i <= group2.size &&
130130
group1.takeRight(i).zip(group2.take(i)).forall {
131-
case (InFirst(first), InSecond(second)) => same(first, second)
132-
case (InSecond(second), InFirst(first)) => same(first, second)
131+
case (InFirst(first), InSecond(second)) => first == second
132+
case (InSecond(second), InFirst(first)) => first == second
133133
case _ => false
134134
}
135135
).lastOption.map { suffixPrefixLength =>
@@ -203,17 +203,14 @@ private[diff] object DiffTokenize {
203203
): List[DiffElement[IndexedSeq[String]]] =
204204
processFirstSecondGroups(diff, _.inSecond)
205205

206-
private def same(s1: IndexedSeq[String], s2: IndexedSeq[String]): Boolean =
207-
s1.size == s2.size && s1.indices.forall(i => s1(i) == s2(i))
208-
209206
def join(diff: List[DiffElement[IndexedSeq[String]]]): List[DiffElement[IndexedSeq[String]]] =
210207
ListScan(diff) {
211-
case InSecond(second) :: InFirst(first) :: tail if same(first, second) =>
208+
case InSecond(second) :: InFirst(first) :: tail if first == second =>
212209
Nil -> (
213210
InBoth(first) :: tail
214211
)
215212

216-
case InFirst(first) :: InSecond(second) :: tail if same(first, second) =>
213+
case InFirst(first) :: InSecond(second) :: tail if first == second =>
217214
Nil -> (
218215
InBoth(first) :: tail
219216
)

0 commit comments

Comments
 (0)