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

Speedup table building #276

Merged
merged 41 commits into from
Jun 25, 2020
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
d3a2d76
Use optional chaining
Jym77 Jun 23, 2020
9f83d40
Make method private
Jym77 Jun 23, 2020
ceb0785
Use null-coalescing operator in update
Jym77 Jun 23, 2020
3383b71
Make method private
Jym77 Jun 23, 2020
ee000f5
Improve default values in update
Jym77 Jun 23, 2020
c0bb99f
Optimize slots resync
Jym77 Jun 23, 2020
e781a4a
Optimize slots resync
Jym77 Jun 23, 2020
4961e23
Optimize slots resync
Jym77 Jun 23, 2020
881d28b
Separate update/add cells
Jym77 Jun 23, 2020
c376c37
Store left/top most data cell
Jym77 Jun 23, 2020
4030c31
Keep memory of column/row with data cells
Jym77 Jun 23, 2020
c9016a0
Use stored data cells in rows/columns
Jym77 Jun 24, 2020
e268968
Merge branch 'master' into speedup-table-building
Jym77 Jun 24, 2020
bcfa444
Move some table logic out of Cell.Builder
Jym77 Jun 24, 2020
652f5f5
Store slot coverage in Row.Builder
Jym77 Jun 24, 2020
10ccc9e
Clean up
Jym77 Jun 24, 2020
77956c5
Clean up
Jym77 Jun 24, 2020
715f84c
Eta-contract call
Jym77 Jun 24, 2020
d63bfe3
Clean up
Jym77 Jun 24, 2020
81e39b1
Store slot coverage in row groups
Jym77 Jun 24, 2020
190ea6e
Try to store growing cells list
Jym77 Jun 24, 2020
96f0809
Simplify code
Jym77 Jun 24, 2020
2a6ec4f
Keep growing cells in Builder instance
Jym77 Jun 24, 2020
203dff6
Fix bug and use updateCells
Jym77 Jun 24, 2020
cb364f5
Clean up after self
Jym77 Jun 24, 2020
bedb0f8
Prepare for storing downward growing cells
Jym77 Jun 24, 2020
c66714a
Fix updateCells
Jym77 Jun 24, 2020
761c5bc
Typo
Jym77 Jun 24, 2020
b321b6b
Allow update of downward growing cells
Jym77 Jun 24, 2020
31a15cf
Allow adding downward growing cells
Jym77 Jun 24, 2020
4b47cb4
Only compute column/rowHasData once before using it
Jym77 Jun 24, 2020
8275de3
Keep downward growing cells in Builder
Jym77 Jun 24, 2020
7e75611
Use stored coverage info for skipIfCovered
Jym77 Jun 24, 2020
90f099f
Clean up
Jym77 Jun 24, 2020
28bd823
Clean up
Jym77 Jun 24, 2020
9eddac3
Add TODO comments
Jym77 Jun 25, 2020
71905fb
Merge branch 'master' into speedup-table-building
Jym77 Jun 25, 2020
437d0b6
Optimize row/column group headers detection
Jym77 Jun 25, 2020
3beb1ae
Optimize coverage checks (table model errors detection)
Jym77 Jun 25, 2020
952e8ae
Merge branch 'master' into speedup-table-building
Jym77 Jun 25, 2020
8b40194
Merge branch 'master' into speedup-table-building
Jym77 Jun 25, 2020
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
97 changes: 31 additions & 66 deletions packages/alfa-table/src/cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,19 @@ export namespace Cell {
this._implicitHeaders = List.from(implicitHeaders);
}

private _update(update: {
private _update({
kind = this.kind,
x = this.anchor.x,
y = this.anchor.y,
width = this.width,
height = this.height,
element = this.element,
variant = this.variant,
downwardGrowing = this._downwardGrowing,
scope = this.scope,
explicitHeaders = this._explicitHeaders,
implicitHeaders = this._implicitHeaders,
}: {
kind?: Cell.Kind;
x?: number;
y?: number;
Expand All @@ -272,23 +284,17 @@ export namespace Cell {
implicitHeaders?: Iterable<Element>;
}): Builder {
return Builder.of(
update.kind !== undefined ? update.kind : this.kind,
update.x !== undefined ? update.x : this.anchor.x,
update.y !== undefined ? update.y : this.anchor.y,
update.width !== undefined ? update.width : this.width,
update.height !== undefined ? update.height : this.height,
update.element !== undefined ? update.element : this.element,
update.variant !== undefined ? update.variant : this.variant,
update.downwardGrowing !== undefined
? update.downwardGrowing
: this._downwardGrowing,
update.scope !== undefined ? update.scope : this.scope,
update.explicitHeaders !== undefined
? update.explicitHeaders
: this._explicitHeaders,
update.implicitHeaders !== undefined
? update.implicitHeaders
: this._implicitHeaders
kind,
x,
y,
width,
height,
element,
variant,
downwardGrowing,
scope,
explicitHeaders,
implicitHeaders
);
}

Expand Down Expand Up @@ -378,41 +384,10 @@ export namespace Cell {
* see @https://html.spec.whatwg.org/multipage/tables.html#column-header
* and following
*/
private _isCoveringArea(
x: number,
y: number,
w: number,
h: number
): boolean {
for (let col = x; col < x + w; col++) {
for (let row = y; row < y + h; row++) {
if (this.isCovering(col, row)) {
return true;
}
}
}
return false;
}

public isDataCoveringArea(
x: number,
y: number,
w: number,
h: number
): boolean {
return this.kind === Cell.Kind.Data && this._isCoveringArea(x, y, w, h);
}

private _scopeToState(
scope: Scope,
existsDataCellCoveringArea: (
x: number,
y: number,
w: number,
h: number
) => boolean,
width: number,
height: number
dataInColumns: boolean, // Is there a data cell in the columns covered by this?
dataInRows: boolean // Is there a data cell in the rows covered by this?
): Option<Scope.Resolved> {
switch (scope) {
// https://html.spec.whatwg.org/multipage/tables.html#column-group-header
Expand All @@ -432,13 +407,9 @@ export namespace Cell {
case Scope.Auto:
// Not entirely clear whether "any of the cells covering slots with y-coordinates y .. y+height-1."
// means "for any x" or just for the x of the cell. Using "for all x"
if (
existsDataCellCoveringArea(0, this.anchor.y, width, this.height)
) {
if (dataInRows) {
// there are *SOME* data cells in any of the cells covering slots with y-coordinates y .. y+height-1.
if (
existsDataCellCoveringArea(this.anchor.x, 0, this.width, height)
) {
if (dataInColumns) {
// there are *SOME* data cells in any of the cells covering slots with x-coordinates x .. x+width-1.
return None;
} else {
Expand All @@ -453,18 +424,12 @@ export namespace Cell {
}

public addHeaderVariant(
existsDataCellCoveringArea: (
x: number,
y: number,
w: number,
h: number
) => boolean,
width: number,
height: number
dataInColumns: boolean, // Is there a data cell in the columns covered by this?
dataInRows: boolean // Is there a data cell in the rows covered by this?
): Builder {
return this._update({
variant: this._scope.flatMap((scope) =>
this._scopeToState(scope, existsDataCellCoveringArea, width, height)
this._scopeToState(scope, dataInColumns, dataInRows)
),
});
}
Expand Down
Loading