Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit a922e59

Browse files
committed
[[ Diff ]] Efficiency improvements: reduce string manipulations in compare_arrays repeat loops
1 parent 6320346 commit a922e59

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

extensions/script-libraries/diff/diff.livecodescript

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -512,9 +512,27 @@ private function compare_arrays pA, pALength, pB, pBLength
512512

513513
end repeat
514514

515-
return tPath[tDelta]
515+
return add_content_to_edits(tPath[tDelta], pA, pB)
516516
end compare_arrays
517517

518+
private function add_content_to_edits pEdits, pA, pB
519+
local tEdits
520+
repeat for each line tEdit in pEdits
521+
local tA, tB, tOperation
522+
put item 2 of tEdit into tOperation
523+
local tContent
524+
if tOperation is kDiffOperationAdd then
525+
put item 3 of tEdit into tB
526+
put pB[tB] into tContent
527+
else
528+
put item 1 of tEdit into tA
529+
put pA[tA] into tContent
530+
end if
531+
put tEdit,tContent & return after tEdits
532+
end repeat
533+
return tEdits
534+
end add_content_to_edits
535+
518536
private command compare_diagonal @pFP, @pPath, @pA, pALength, @pB, pBLength, k
519537
local tLeft, tRight, tNext, tPrevPath, tOperation, tContent
520538
put pFP[k - 1] + 1 into tLeft
@@ -523,16 +541,14 @@ private command compare_diagonal @pFP, @pPath, @pA, pALength, @pB, pBLength, k
523541
put pPath[k - 1] into tPrevPath
524542
put kDiffOperationAdd into tOperation
525543
put tLeft into tNext
526-
put pB[tNext] into tContent
527544
else
528545
put pPath[k + 1] into tPrevPath
529546
put kDiffOperationDelete into tOperation
530547
put tRight into tNext
531-
put pA[tNext - k] into tContent
532548
end if
533549

534550
if k > 0 or tNext > 0 then
535-
put tPrevPath & format_edit(tNext - k, tNext, tOperation, tContent) & return into pPath[k]
551+
put tPrevPath & tNext-k,tOperation,tNext & cr into pPath[k]
536552
end if
537553
local tP
538554
put snake(pA, pALength, pB, pBLength, k, tNext) into pFP[k]

0 commit comments

Comments
 (0)