diff --git a/html/commit.js b/html/commit.js
index 1ed2058..05cb596 100644
--- a/html/commit.js
+++ b/html/commit.js
@@ -139,7 +139,7 @@ var loadCommit = function() {
$("message").innerHTML = commit.message.replace(/\n/g,"
");
- if (commit.diff.length < 10000) {
+ if (commit.diff.length < 200000) {
showDiffs();
} else {
$("details").innerHTML = "This is a large commit. Click here or press 'v' to view.";
diff --git a/html/diffHighlighter.js b/html/diffHighlighter.js
index 43274bd..fc0f1e4 100644
--- a/html/diffHighlighter.js
+++ b/html/diffHighlighter.js
@@ -1,63 +1,65 @@
-var EMPTY_SIDE = " \n";
+
+// If we run from a Safari instance, we don't
+// have a Controller object. Instead, we fake it by
+// using the console
+if (typeof Controller == 'undefined')
+{
+ Controller = console;
+ Controller.log_ = console.log;
+}
+
var highlightDiffs = function() {
+ var start = new Date().getTime();
var diffs = document.getElementsByClassName("diffcode");
- $A(diffs).each(function(diff) {
- var content = diff.innerHTML.strip();
- diff.innerHTML = "";
+ for (var diffn = 0; diffn < diffs.length; diffn++) {
+ var diff = diffs[diffn];
+
+ var content = diff.innerHTML.replace(/\s+$/, '');
var line1 = "";
var line2 = "";
var diffContent = "";
- var lines = $A(content.split("\n"));
+ var lines = content.split('\n');
var hunk_start_line_1 = -1;
var hunk_start_line_2 = -1;
- var start = new Date();
- lines.each(function(l) {
- if (l.length > 250)
- l = l.substring(0, 250);
+ var header = false;
- l = l.gsub("\t", " ");
+ for (var lineno = 0; lineno < lines.length; lineno++) {
+ var l = lines[lineno];
- if (l.startsWith("diff")) {
- line1 += "\n";
- line2 += "\n";
- diffContent += "
";
- return;
- }
- if (l.startsWith("---")) {
- return;
- line1 += "\n";
- line2 += "\n";
- diffContent += "" + l + "
";
- return;
+ var firstChar = l.charAt(0);
+
+ if (header) {
+ if (firstChar == "+" || firstChar == "-")
+ continue;
+ } else if (firstChar == "d") {
+ header = true;
+ line1 += '\n';
+ line2 += '\n';
+ diffContent += '';
+ continue;
}
- if (l.startsWith("+++")) {
- return;
- line1 += "\n";
- line2 += "\n";
- diffContent += "" + l + "
";
- return;
- }
-
- if (l.startsWith("+")) {
+ l = l.replace(/\t/g, " ");
+ if (firstChar == "+") {
// Highlight trailing whitespace
- if (m = l.match(/([\t ]+)$/))
- l = l.replace(/[\t ]+$/, "" + m[1] + "");
+ if (m = l.match(/\s+$/))
+ l = l.replace(/\s+$/, "" + m + "");
line1 += "\n";
line2 += ++hunk_start_line_2 + "\n";
diffContent += "" + l + "
";
}
- else if (l.startsWith("-")) {
+ else if (firstChar == "-") {
line1 += ++hunk_start_line_1 + "\n";
line2 += "\n";
diffContent += "" + l + "
";
}
- else if (l.startsWith("@"))
+ else if (firstChar == "@")
{
+ header = false;
if (m = l.match(/@@ \-([0-9]+),\d+ \+(\d+),\d+ @@/))
{
hunk_start_line_1 = parseInt(m[1]) - 1;
@@ -67,17 +69,22 @@ var highlightDiffs = function() {
line2 += "...\n";
diffContent += "";
}
- else if (l.startsWith(" "))
+ else if (firstChar == " ")
{
line1 += ++hunk_start_line_1 + "\n";
line2 += ++hunk_start_line_2 + "\n";
diffContent += l + "\n";
}
- });
- var duration = new Date() - start;
- var new_content = "" + line1 + " | ";
- new_content += "" + line2 + " | ";
- new_content += "" + diffContent + " |
";
- diff.innerHTML = new_content;
- });
+ }
+
+
+ // This takes about 7ms
+ diff.innerHTML = "" + line1 + " | " +
+ "" + line2 + " | " +
+ "" + diffContent + " |
";
+
+ }
+ // TODO: Replace this with a performance pref call
+ if (false)
+ Controller.log_("Total time:" + (new Date().getTime() - start));
}
\ No newline at end of file