Commit a4c5b69
committed
Do not repeatedly concatenate lines when parsing diffs
Because string concatenation has to allocate a new string for each
allocation the time required for concatenating `n` lines is `O(n^2)`
(with a constant depending on the line length). This can be optimised to
`O(n)` (this is the purpose of `StringBuilder` after all).
In this case a list of lines is used because this avoids problems with
line ending encoding (which is currently handled by always using "\r\n"
internally). This also makes it easier to insert symbols at the start of
the line (for example plus or minus for diff types).
The use sites of the `DiffNode` label are refactored to prevent
duplicate work (for example joining lines and immediately splitting them again).1 parent 32c9dea commit a4c5b69
6 files changed
Lines changed: 51 additions & 25 deletions
File tree
- src/main/java/org/variantsync/diffdetective/diff/difftree
- parse
- serialize/nodeformat
- transform
Lines changed: 36 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
32 | | - | |
| 33 | + | |
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
| |||
59 | 60 | | |
60 | 61 | | |
61 | 62 | | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
62 | 70 | | |
63 | 71 | | |
64 | 72 | | |
65 | 73 | | |
66 | 74 | | |
67 | 75 | | |
68 | | - | |
| 76 | + | |
69 | 77 | | |
70 | 78 | | |
71 | 79 | | |
| |||
79 | 87 | | |
80 | 88 | | |
81 | 89 | | |
82 | | - | |
| 90 | + | |
83 | 91 | | |
84 | 92 | | |
85 | 93 | | |
86 | 94 | | |
87 | 95 | | |
88 | 96 | | |
89 | 97 | | |
90 | | - | |
91 | | - | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
92 | 108 | | |
93 | 109 | | |
94 | 110 | | |
95 | | - | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
96 | 117 | | |
97 | 118 | | |
98 | 119 | | |
| |||
680 | 701 | | |
681 | 702 | | |
682 | 703 | | |
683 | | - | |
| 704 | + | |
684 | 705 | | |
685 | 706 | | |
686 | 707 | | |
| |||
694 | 715 | | |
695 | 716 | | |
696 | 717 | | |
697 | | - | |
| 718 | + | |
698 | 719 | | |
699 | 720 | | |
700 | 721 | | |
| |||
737 | 758 | | |
738 | 759 | | |
739 | 760 | | |
740 | | - | |
741 | | - | |
| 761 | + | |
| 762 | + | |
742 | 763 | | |
743 | 764 | | |
744 | 765 | | |
745 | | - | |
| 766 | + | |
746 | 767 | | |
747 | 768 | | |
748 | 769 | | |
| |||
758 | 779 | | |
759 | 780 | | |
760 | 781 | | |
| 782 | + | |
761 | 783 | | |
762 | 784 | | |
763 | | - | |
| 785 | + | |
764 | 786 | | |
765 | 787 | | |
766 | 788 | | |
| |||
786 | 808 | | |
787 | 809 | | |
788 | 810 | | |
789 | | - | |
| 811 | + | |
790 | 812 | | |
791 | 813 | | |
792 | 814 | | |
793 | 815 | | |
794 | | - | |
| 816 | + | |
795 | 817 | | |
796 | 818 | | |
Lines changed: 5 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
10 | 12 | | |
11 | 13 | | |
12 | 14 | | |
| |||
28 | 30 | | |
29 | 31 | | |
30 | 32 | | |
| 33 | + | |
| 34 | + | |
31 | 35 | | |
32 | 36 | | |
33 | 37 | | |
34 | 38 | | |
35 | | - | |
| 39 | + | |
36 | 40 | | |
37 | 41 | | |
Lines changed: 5 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
82 | | - | |
83 | | - | |
84 | | - | |
| 82 | + | |
| 83 | + | |
85 | 84 | | |
86 | 85 | | |
87 | 86 | | |
| |||
133 | 132 | | |
134 | 133 | | |
135 | 134 | | |
136 | | - | |
| 135 | + | |
137 | 136 | | |
138 | 137 | | |
139 | 138 | | |
| |||
149 | 148 | | |
150 | 149 | | |
151 | 150 | | |
| 151 | + | |
152 | 152 | | |
153 | 153 | | |
154 | 154 | | |
| |||
160 | 160 | | |
161 | 161 | | |
162 | 162 | | |
163 | | - | |
| 163 | + | |
164 | 164 | | |
165 | 165 | | |
166 | 166 | | |
| |||
Lines changed: 1 addition & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
23 | | - | |
24 | | - | |
| 22 | + | |
25 | 23 | | |
26 | 24 | | |
27 | 25 | | |
| |||
Lines changed: 3 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
| 116 | + | |
| 117 | + | |
116 | 118 | | |
117 | 119 | | |
118 | 120 | | |
119 | 121 | | |
120 | | - | |
| 122 | + | |
121 | 123 | | |
122 | 124 | | |
123 | 125 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
80 | | - | |
| 80 | + | |
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
| |||
0 commit comments