From 55858121b5451576eb1e048d9012e44a3e6c0580 Mon Sep 17 00:00:00 2001 From: 13372038054 <550906320@qq.com> Date: Sat, 11 Nov 2017 14:19:04 +0800 Subject: [PATCH] optimize the parse of diff source, use StringBuilder --- .../openhub/ui/widget/webview/HtmlHelper.java | 43 ++++++++++--------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/com/thirtydegreesray/openhub/ui/widget/webview/HtmlHelper.java b/app/src/main/java/com/thirtydegreesray/openhub/ui/widget/webview/HtmlHelper.java index 00052b70..095d556a 100644 --- a/app/src/main/java/com/thirtydegreesray/openhub/ui/widget/webview/HtmlHelper.java +++ b/app/src/main/java/com/thirtydegreesray/openhub/ui/widget/webview/HtmlHelper.java @@ -5,6 +5,7 @@ import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import com.orhanobut.logger.Logger; import com.thirtydegreesray.openhub.mvp.model.GitHubName; import com.thirtydegreesray.openhub.util.GitHubHelper; import com.thirtydegreesray.openhub.util.StringUtils; @@ -171,13 +172,13 @@ private static String generateDiffHtml(@NonNull String diffSource, @NonNull Stri "" + "\n" + "" + + "body {background: " + backgroundColor + ";}\n" + + ".pre {\n" + + "background: " + backgroundColor + ";\n" + + " word-wrap: " + (wrap ? "break-word" : "normal") + ";\n" + + " white-space: " + (wrap ? "pre-wrap" : "pre") + ";\n" + + "}\n" + + "\n" + "\n" + "
\n" + @@ -189,7 +190,7 @@ private static String generateDiffHtml(@NonNull String diffSource, @NonNull Stri } private static String parseDiffSource(@NonNull String diffSource, boolean wrap) { - String source = ""; + StringBuilder source = new StringBuilder(); String[] lines = diffSource.split("\\n"); int addStartLine = -1; @@ -221,7 +222,7 @@ private static String parseDiffSource(@NonNull String diffSource, boolean wrap) addLineNum = 0; removeLineNum = 0; normalLineNum = 0; - } else { + } else if (!line.startsWith("\\")) { curAddNumber = addStartLine + normalLineNum + addLineNum; curRemoveNumber = removeStartLine + normalLineNum + removeLineNum; normalLineNum++; @@ -229,22 +230,24 @@ private static String parseDiffSource(@NonNull String diffSource, boolean wrap) lineNumberStr = getDiffLineNumber(curRemoveNumber == -1 ? "" : String.valueOf(curRemoveNumber), curAddNumber == -1 ? "" : String.valueOf(curAddNumber)); - - String lineHtml = "