Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,24 +8,21 @@ import 'dart:isolate'; | |
/// Creates a single hitmap from a raw json object. Throws away all entries that | ||
/// are not resolvable. | ||
Map createHitmap(List<Map> json) { | ||
Map<String, Map<int, int>> hitMap = {}; | ||
Map<String, Map<int, int>> hitMap = <String, Map<int, int>>{}; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
cbracken
Member
|
||
|
||
addToMap(source, line, count) { | ||
if (!hitMap[source].containsKey(line)) { | ||
hitMap[source][line] = 0; | ||
} | ||
hitMap[source][line] += count; | ||
void addToMap(Map<int, int> map, int line, int count) { | ||
var oldCount = map.putIfAbsent(line, () => 0); | ||
map[line] = count + oldCount; | ||
} | ||
|
||
json.forEach((Map e) { | ||
for (Map e in json) { | ||
var source = e['source']; | ||
if (source == null) { | ||
// Couldnt resolve import, so skip this entry. | ||
return; | ||
} | ||
if (!hitMap.containsKey(source)) { | ||
hitMap[source] = {}; | ||
// Couldn't resolve import, so skip this entry. | ||
continue; | ||
} | ||
|
||
var childHitMap = hitMap.putIfAbsent(source, () => <int, int>{}); | ||
This comment has been minimized.
Sorry, something went wrong.
cbracken
Member
|
||
var hits = e['hits']; | ||
// hits is a flat array of the following format: | ||
// [ <line|linerange>, <hitcount>,...] | ||
|
@@ -35,19 +32,19 @@ Map createHitmap(List<Map> json) { | |
var k = hits[i]; | ||
if (k is num) { | ||
// Single line. | ||
addToMap(source, k, hits[i + 1]); | ||
addToMap(childHitMap, k, hits[i + 1]); | ||
} | ||
if (k is String) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
kevmoo
Author
Member
|
||
// Linerange. We expand line ranges to actual lines at this point. | ||
var splitPos = k.indexOf('-'); | ||
int start = int.parse(k.substring(0, splitPos)); | ||
int end = int.parse(k.substring(splitPos + 1, k.length)); | ||
This comment has been minimized.
Sorry, something went wrong.
cbracken
Member
|
||
for (var j = start; j <= end; j++) { | ||
addToMap(source, j, hits[i + 1]); | ||
addToMap(childHitMap, j, hits[i + 1]); | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
return hitMap; | ||
} | ||
|
||
|
var hitMap = ...