Move syntax highlighting back to client

Mozilla Rhino is just slow running the JavaScript for prettify.
Its quicker inside of most modern browsers, especially ones that
have a good JIT like Goole Chrome or Safari 4.

Move the rendering back onto the client side.  To do this correctly
we have to ship the entire file to the client.  So what we do is,
we send the entire "A" file, the old image, and only the new lines
from the "B" file, the new image.  When formatting locally on the
client we recreate the full "B" file in order to syntax highlight it.

If a file is considered large, over 9000 lines, we still only send
part of the file and we disable the syntax highlighting.  This way
the client doesn't get bogged down in rendering lots of text when
the file is something really massive.

Bug: issue 439
Change-Id: Ib70c6526af09f84ebbfe467cfbb27c75ca7c9ad7
Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
Shawn O. Pearce
2010-02-16 11:02:36 -08:00
parent 6caaa60a2d
commit 47cfa6d8cf
11 changed files with 414 additions and 180 deletions

View File

@@ -26,7 +26,7 @@ import com.google.gerrit.common.data.AccountInfo;
import com.google.gerrit.common.data.AccountInfoCache;
import com.google.gerrit.common.data.CommentDetail;
import com.google.gerrit.common.data.PatchScript;
import com.google.gerrit.common.data.SparseFileContent;
import com.google.gerrit.prettify.common.SparseFileContent;
import com.google.gerrit.reviewdb.Patch;
import com.google.gerrit.reviewdb.PatchLineComment;
import com.google.gerrit.reviewdb.PatchSet;

View File

@@ -21,9 +21,9 @@ import static com.google.gerrit.client.patches.PatchLine.Type.REPLACE;
import com.google.gerrit.client.Gerrit;
import com.google.gerrit.common.data.CommentDetail;
import com.google.gerrit.common.data.EditList;
import com.google.gerrit.common.data.PatchScript;
import com.google.gerrit.common.data.SparseFileContent;
import com.google.gerrit.prettify.common.EditList;
import com.google.gerrit.prettify.common.SparseHtmlFile;
import com.google.gerrit.reviewdb.Patch;
import com.google.gerrit.reviewdb.PatchLineComment;
import com.google.gwt.core.client.GWT;
@@ -67,8 +67,8 @@ public class SideBySideTable extends AbstractPatchContentTable {
@Override
protected void render(final PatchScript script) {
final SparseFileContent a = script.getA();
final SparseFileContent b = script.getB();
final SparseHtmlFile a = script.getSparseHtmlFileA();
final SparseHtmlFile b = script.getSparseHtmlFileB();
final ArrayList<PatchLine> lines = new ArrayList<PatchLine>();
final SafeHtmlBuilder nc = new SafeHtmlBuilder();
@@ -86,7 +86,7 @@ public class SideBySideTable extends AbstractPatchContentTable {
while (hunk.next()) {
if (hunk.isContextLine()) {
openLine(nc);
final SafeHtml ctx = a.get(hunk.getCurA());
final SafeHtml ctx = a.getSafeHtmlLine(hunk.getCurA());
appendLineText(nc, hunk.getCurA(), CONTEXT, ctx);
if (ignoreWS && b.contains(hunk.getCurB())) {
appendLineText(nc, hunk.getCurB(), CONTEXT, b, hunk.getCurB());
@@ -273,8 +273,8 @@ public class SideBySideTable extends AbstractPatchContentTable {
private void appendLineText(final SafeHtmlBuilder m,
final int lineNumberMinusOne, final PatchLine.Type type,
final SparseFileContent src, final int i) {
appendLineText(m, lineNumberMinusOne, type, src.get(i));
final SparseHtmlFile src, final int i) {
appendLineText(m, lineNumberMinusOne, type, src.getSafeHtmlLine(i));
}
private void appendLineText(final SafeHtmlBuilder m,

View File

@@ -20,11 +20,11 @@ import static com.google.gerrit.client.patches.PatchLine.Type.INSERT;
import com.google.gerrit.client.Gerrit;
import com.google.gerrit.common.data.CommentDetail;
import com.google.gerrit.common.data.EditList;
import com.google.gerrit.common.data.PatchScript;
import com.google.gerrit.common.data.SparseFileContent;
import com.google.gerrit.common.data.EditList.Hunk;
import com.google.gerrit.common.data.PatchScript.DisplayMethod;
import com.google.gerrit.prettify.common.EditList;
import com.google.gerrit.prettify.common.SparseHtmlFile;
import com.google.gerrit.prettify.common.EditList.Hunk;
import com.google.gerrit.reviewdb.Patch;
import com.google.gerrit.reviewdb.PatchLineComment;
import com.google.gwt.core.client.GWT;
@@ -86,8 +86,8 @@ public class UnifiedDiffTable extends AbstractPatchContentTable {
@Override
protected void render(final PatchScript script) {
final SparseFileContent a = script.getA();
final SparseFileContent b = script.getB();
final SparseHtmlFile a = script.getSparseHtmlFileA();
final SparseHtmlFile b = script.getSparseHtmlFileB();
final SafeHtmlBuilder nc = new SafeHtmlBuilder();
// Display the patch header
@@ -153,8 +153,10 @@ public class UnifiedDiffTable extends AbstractPatchContentTable {
closeLine(nc);
hunk.incA();
lines.add(new PatchLine(DELETE, hunk.getCurA(), 0));
if (a.size() == hunk.getCurA() && a.isMissingNewlineAtEnd())
if (a.size() == hunk.getCurA()
&& script.getA().isMissingNewlineAtEnd()) {
appendNoLF(nc);
}
} else if (hunk.isInsertedB()) {
openLine(nc);
@@ -164,8 +166,10 @@ public class UnifiedDiffTable extends AbstractPatchContentTable {
closeLine(nc);
hunk.incB();
lines.add(new PatchLine(INSERT, 0, hunk.getCurB()));
if (b.size() == hunk.getCurB() && b.isMissingNewlineAtEnd())
if (b.size() == hunk.getCurB()
&& script.getB().isMissingNewlineAtEnd()) {
appendNoLF(nc);
}
}
}
}
@@ -304,8 +308,8 @@ public class UnifiedDiffTable extends AbstractPatchContentTable {
}
private void appendLineText(final SafeHtmlBuilder m,
final PatchLine.Type type, final SparseFileContent src, final int i) {
final SafeHtml text = src.get(i);
final PatchLine.Type type, final SparseHtmlFile src, final int i) {
final SafeHtml text = src.getSafeHtmlLine(i);
m.openTd();
m.addStyleName(Gerrit.RESOURCES.css().diffText());
switch (type) {