[extensions-web] review: Don't use an array as a structure
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [extensions-web] review: Don't use an array as a structure
- Date: Tue, 26 Jun 2012 20:23:54 +0000 (UTC)
commit bdf792a02ef9abcfdd2959b1dead68756fe12934
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Tue Jun 26 13:07:18 2012 -0400
review: Don't use an array as a structure
It's inconvenient for JSON. At the same time, remove the unused vlinenum.
sweettooth/review/diffutils.py | 17 +++++------------
sweettooth/static/js/diff.js | 27 +++++++++------------------
2 files changed, 14 insertions(+), 30 deletions(-)
---
diff --git a/sweettooth/review/diffutils.py b/sweettooth/review/diffutils.py
index 0bfd213..c716222 100644
--- a/sweettooth/review/diffutils.py
+++ b/sweettooth/review/diffutils.py
@@ -756,25 +756,19 @@ def new_chunk(lines, collapsable=False, tag='equal', meta=None):
def get_fake_chunk(numlines, tag):
linenums = xrange(numlines)
- lines = [[n+1, n+1, n+1, [], []] for n in linenums]
+ lines = [dict(oldlinenum=n+1, newlinenum=n+1,
+ oldregion=[], newregion=[]) for n in linenums]
return new_chunk(lines, tag=tag)
def get_chunks(a, b):
- def diff_line(vlinenum, oldlinenum, newlinenum, oldline, newline):
- # This function accesses the variable meta, defined in an outer context.
+ def diff_line(oldlinenum, newlinenum, oldline, newline):
if oldline and newline and oldline != newline:
oldregion, newregion = get_line_changed_regions(oldline, newline)
else:
oldregion = newregion = []
- result = [vlinenum, oldlinenum, newlinenum, oldregion, newregion]
-
- if oldlinenum and oldlinenum in meta.get('moved', {}):
- destination = meta["moved"][oldlinenum]
- result.append(destination)
- elif newlinenum and newlinenum in meta.get('moved', {}):
- destination = meta["moved"][newlinenum]
- result.append(destination)
+ result = dict(oldlinenum=oldlinenum, newlinenum=newlinenum,
+ oldregion=oldregion, newregion=newregion)
return result
@@ -801,7 +795,6 @@ def get_chunks(a, b):
numlines = max(i2-i1, j2-j1)
lines = map(diff_line,
- xrange(linenum, linenum + numlines),
xrange(i1 + 1, i2 + 1), xrange(j1 + 1, j2 + 1),
a[i1:i2], b[j1:j2])
diff --git a/sweettooth/static/js/diff.js b/sweettooth/static/js/diff.js
index be1f313..1cce33e 100644
--- a/sweettooth/static/js/diff.js
+++ b/sweettooth/static/js/diff.js
@@ -45,14 +45,11 @@ define(['jquery'], function($) {
var collapsed = false;
var $elems = $.map(chunk.lines, function(line, i) {
- var oldLinum = line[1];
- var newLinum = line[2];
-
- var contents = oldContents[oldLinum - 1];
+ var contents = oldContents[line.oldlinenum - 1];
var $row = $('<tr>', {'class': 'diff-line equal'}).
- append($('<td>', {'class': 'old linum'}).text(oldLinum)).
- append($('<td>', {'class': 'new linum'}).text(newLinum)).
+ append($('<td>', {'class': 'old linum'}).text(line.oldlinenum)).
+ append($('<td>', {'class': 'new linum'}).text(line.newlinenum)).
append($('<td>', {'class': 'new contents'}).text(contents));
if (chunk.collapsable) {
@@ -129,15 +126,12 @@ define(['jquery'], function($) {
}
function buildInsertLine(line, contents) {
- var linum = line[2];
- var content = contents[linum - 1];
- var region = line[4];
-
+ var content = contents[line.newlinenum - 1];
return $('<tr>', {'class': 'diff-line inserted'}).
append($('<td>', {'class': 'linum'})).
- append($('<td>', {'class': 'new linum'}).text(linum)).
+ append($('<td>', {'class': 'new linum'}).text(line.newlinenum)).
append($('<td>', {'class': 'new contents'}).
- append(flatten(buildReplaceRegions(region, content))));
+ append(flatten(buildReplaceRegions(line.newregion, content))));
}
function buildInsertChunk(chunk, oldContents, newContents) {
@@ -145,15 +139,12 @@ define(['jquery'], function($) {
}
function buildDeleteLine(line, contents) {
- var linum = line[1];
- var content = contents[linum - 1];
- var region = line[3];
-
+ var content = contents[line.oldlinenum];
return $('<tr>', {'class': 'diff-line deleted'}).
- append($('<td>', {'class': 'old linum'}).text(linum)).
+ append($('<td>', {'class': 'old linum'}).text(line.oldlinenum)).
append($('<td>', {'class': 'linum'})).
append($('<td>', {'class': 'old contents'}).
- append(flatten(buildReplaceRegions(region, content))));
+ append(flatten(buildReplaceRegions(line.oldregion, content))));
}
function buildDeleteChunk(chunk, oldContents, newContents) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]