|
19 | 19 | package name.fraser.neil.plaintext; |
20 | 20 |
|
21 | 21 | import java.io.UnsupportedEncodingException; |
22 | | -import java.lang.Character; |
23 | | -import java.net.URLDecoder; |
24 | 22 | import java.net.URLEncoder; |
25 | | -import java.util.*; |
| 23 | +import java.nio.charset.StandardCharsets; |
| 24 | +import java.util.ArrayDeque; |
| 25 | +import java.util.ArrayList; |
| 26 | +import java.util.Arrays; |
| 27 | +import java.util.Deque; |
| 28 | +import java.util.HashMap; |
| 29 | +import java.util.HashSet; |
| 30 | +import java.util.LinkedList; |
| 31 | +import java.util.List; |
| 32 | +import java.util.ListIterator; |
| 33 | +import java.util.Map; |
26 | 34 | import java.util.regex.Matcher; |
27 | 35 | import java.util.regex.Pattern; |
28 | 36 |
|
@@ -138,7 +146,7 @@ public LinkedList<Diff> diff_main(String text1, String text2, |
138 | 146 | if (Diff_Timeout <= 0) { |
139 | 147 | deadline = Long.MAX_VALUE; |
140 | 148 | } else { |
141 | | - deadline = System.currentTimeMillis() + (long) (Diff_Timeout * 1000); |
| 149 | + deadline = System.nanoTime() + (long) (Diff_Timeout * 1000000000l); |
142 | 150 | } |
143 | 151 | return diff_main(text1, text2, checklines, deadline); |
144 | 152 | } |
@@ -382,7 +390,7 @@ protected LinkedList<Diff> diff_bisect(String text1, String text2, |
382 | 390 | int k2end = 0; |
383 | 391 | for (int d = 0; d < max_d; d++) { |
384 | 392 | // Bail out if deadline is reached. |
385 | | - if (System.currentTimeMillis() > deadline) { |
| 393 | + if (System.nanoTime() > deadline) { |
386 | 394 | break; |
387 | 395 | } |
388 | 396 |
|
@@ -1474,13 +1482,8 @@ public String diff_toDelta(List<Diff> diffs) { |
1474 | 1482 | for (Diff aDiff : diffs) { |
1475 | 1483 | switch (aDiff.operation) { |
1476 | 1484 | case INSERT: |
1477 | | - try { |
1478 | | - text.append("+").append(URLEncoder.encode(aDiff.text, "UTF-8") |
1479 | | - .replace('+', ' ')).append("\t"); |
1480 | | - } catch (UnsupportedEncodingException e) { |
1481 | | - // Not likely on modern system. |
1482 | | - throw new Error("This system does not support UTF-8.", e); |
1483 | | - } |
| 1485 | + text.append("+").append(URLEncoder.encode(aDiff.text, StandardCharsets.UTF_8) |
| 1486 | + .replace('+', ' ')).append("\t"); |
1484 | 1487 | break; |
1485 | 1488 | case DELETE: |
1486 | 1489 | text.append("-").append(aDiff.text.length()).append("\t"); |
|
0 commit comments