Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try some changes to see whether HTML report performance gets better #1778

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 17 additions & 19 deletions coverage/htmlfiles/coverage_html.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,13 @@ function on_click(sel, fn) {
// Helpers for table sorting
function getCellValue(row, column = 0) {
const cell = row.cells[column] // nosemgrep: eslint.detect-object-injection
if (cell.childElementCount == 1) {
var child = cell.firstElementChild;
if (child.tagName === "A") {
child = child.firstElementChild;
}
if (child instanceof HTMLDataElement && child.value) {
return child.value;
}
}
return cell.innerText || cell.textContent;
}

function rowComparator(rowA, rowB, column = 0) {
let valueA = getCellValue(rowA, column);
let valueB = getCellValue(rowB, column);
if (!isNaN(valueA) && !isNaN(valueB)) {
if (!Number.isNaN(valueA - valueB)) {
return valueA - valueB;
}
return valueA.localeCompare(valueB, undefined, {numeric: true});
Expand All @@ -60,7 +51,6 @@ function sortColumn(th) {
// Get the current sorting direction of the selected header,
// clear state on other headers and then set the new sorting direction.
const currentSortOrder = th.getAttribute("aria-sort");
[...th.parentElement.cells].forEach(header => header.setAttribute("aria-sort", "none"));
var direction;
if (currentSortOrder === "none") {
direction = th.dataset.defaultSortOrder || "ascending";
Expand All @@ -71,14 +61,20 @@ function sortColumn(th) {
else {
direction = "ascending";
}
th.setAttribute("aria-sort", direction);

const column = [...th.parentElement.cells].indexOf(th)
const tbody = th.closest("table").querySelector("tbody");
// Sort all rows
const sorted = Array.from(tbody.rows)
.sort((rowA, rowB) => rowComparator(rowA, rowB, column) * (direction === "ascending" ? 1 : -1));

// Use a document fragment to attach rows
const doc_fragment = document.createDocumentFragment();
sorted.forEach(row => doc_fragment.appendChild(row));
tbody.replaceChildren(doc_fragment);

// Sort all rows and afterwards append them in order to move them in the DOM.
Array.from(th.closest("table").querySelectorAll("tbody tr"))
.sort((rowA, rowB) => rowComparator(rowA, rowB, column) * (direction === "ascending" ? 1 : -1))
.forEach(tr => tr.parentElement.appendChild(tr));
[...th.parentElement.cells].forEach(header => header.setAttribute("aria-sort", "none"));
th.setAttribute("aria-sort", direction);

// Save the sort order for next time.
if (th.id !== "region") {
Expand Down Expand Up @@ -250,9 +246,11 @@ coverage.wire_up_filter = function () {
document.getElementById("hide100").addEventListener("input", debounce(filter_handler));

// Trigger change event on setup, to force filter on page refresh
// (filter value may still be present).
document.getElementById("filter").dispatchEvent(new Event("input"));
document.getElementById("hide100").dispatchEvent(new Event("input"));
// if there is either a saved filter or hide 100% value.
if (saved_hide100_value || saved_filter_value) {
document.getElementById("filter").dispatchEvent(new Event("input"));
document.getElementById("hide100").dispatchEvent(new Event("input"));
}
};
coverage.FILTER_STORAGE = "COVERAGE_FILTER_VALUE";
coverage.HIDE100_STORAGE = "COVERAGE_HIDE100_VALUE";
Expand Down