Skip to content

Commit f8153c9

Browse files
committed
Optimize Patch.diff for the case where files are not different
1 parent 091a673 commit f8153c9

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/patch.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ let diff_op operation a b =
338338
{operation; hunks; mine_no_nl; their_no_nl}
339339
in
340340
match l1, l2 with
341-
| [], [] | [""], [""] when mine = [] && their = [] -> None
341+
| [], [] | [""], [""] when mine = [] && their = [] -> assert false
342342
| [], [] -> Some (create_diff ~mine_no_nl:true ~their_no_nl:true)
343343
| [""], [] -> Some (create_diff ~mine_no_nl:false ~their_no_nl:true)
344344
| [], [""] -> Some (create_diff ~mine_no_nl:true ~their_no_nl:false)
@@ -373,4 +373,5 @@ let diff operation a b = match a, b with
373373
| None, None -> invalid_arg "no input given"
374374
| None, Some b -> diff_op operation "" b
375375
| Some a, None -> diff_op operation a ""
376+
| Some a, Some b when String.equal a b -> None (* NOTE: Optimization *)
376377
| Some a, Some b -> diff_op operation a b

0 commit comments

Comments
 (0)