|
@@ -12236,10 +12236,10 @@ static void layout_grid_auto(struct lay *l, unsigned int parent,
|
|
|
/* Column widths are the widest cell in each column across every row, so all
|
|
/* Column widths are the widest cell in each column across every row, so all
|
|
|
* rows line up. The table model is still deliberately basic: no colspan,
|
|
* rows line up. The table model is still deliberately basic: no colspan,
|
|
|
* border-collapse or percentage columns. */
|
|
* border-collapse or percentage columns. */
|
|
|
-static void table_columns(struct lay *l, unsigned int table,
|
|
|
|
|
- const struct br_style *pst, int avail,
|
|
|
|
|
- int *raw, int maxcols, int *out_cols,
|
|
|
|
|
- int *out_total)
|
|
|
|
|
|
|
+static void table_columns_compute(struct lay *l, unsigned int table,
|
|
|
|
|
+ const struct br_style *pst, int avail,
|
|
|
|
|
+ int *raw, int maxcols, int *out_cols,
|
|
|
|
|
+ int *out_total)
|
|
|
{
|
|
{
|
|
|
unsigned int r, c;
|
|
unsigned int r, c;
|
|
|
int cols = 0, total = 0, fixed_sum = 0, free_raw = 0, free_cols = 0;
|
|
int cols = 0, total = 0, fixed_sum = 0, free_raw = 0, free_cols = 0;
|
|
@@ -12409,6 +12409,56 @@ static void table_columns(struct lay *l, unsigned int table,
|
|
|
*out_total = total;
|
|
*out_total = total;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+/* Every row of a fallback table asks for the same column widths, and each
|
|
|
|
|
+ * computation measures the text of every cell of every row: a Hacker News
|
|
|
|
|
+ * comment page (one row per comment) spent ~1.7 s per layout pass in this
|
|
|
|
|
+ * O(rows^2) walk. The result is cached per table, width and layout pass
|
|
|
|
|
+ * (inline_box_pass_id changes with every measure/render pass, so a DOM or
|
|
|
|
|
+ * style change is never served stale widths). */
|
|
|
|
|
+#define TCOL_CACHE 8 /* nested tables: one slot per nesting level */
|
|
|
|
|
+static struct {
|
|
|
|
|
+ unsigned int table, pass;
|
|
|
|
|
+ int avail, maxcols, cols, total;
|
|
|
|
|
+ int raw[12];
|
|
|
|
|
+ int valid;
|
|
|
|
|
+} tcol_cache[TCOL_CACHE];
|
|
|
|
|
+static unsigned int tcol_next;
|
|
|
|
|
+
|
|
|
|
|
+static void table_columns(struct lay *l, unsigned int table,
|
|
|
|
|
+ const struct br_style *pst, int avail,
|
|
|
|
|
+ int *raw, int maxcols, int *out_cols,
|
|
|
|
|
+ int *out_total)
|
|
|
|
|
+{
|
|
|
|
|
+ int i, k;
|
|
|
|
|
+
|
|
|
|
|
+ for (k = 0; k < TCOL_CACHE && maxcols <= 12; k++) {
|
|
|
|
|
+ if (!tcol_cache[k].valid || tcol_cache[k].table != table ||
|
|
|
|
|
+ tcol_cache[k].pass != inline_box_pass_id ||
|
|
|
|
|
+ tcol_cache[k].avail != avail ||
|
|
|
|
|
+ tcol_cache[k].maxcols != maxcols)
|
|
|
|
|
+ continue;
|
|
|
|
|
+ for (i = 0; i < maxcols; i++)
|
|
|
|
|
+ raw[i] = tcol_cache[k].raw[i];
|
|
|
|
|
+ *out_cols = tcol_cache[k].cols;
|
|
|
|
|
+ *out_total = tcol_cache[k].total;
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ table_columns_compute(l, table, pst, avail, raw, maxcols, out_cols,
|
|
|
|
|
+ out_total);
|
|
|
|
|
+ if (maxcols > 12)
|
|
|
|
|
+ return;
|
|
|
|
|
+ k = (int)(tcol_next++ % TCOL_CACHE);
|
|
|
|
|
+ tcol_cache[k].table = table;
|
|
|
|
|
+ tcol_cache[k].pass = inline_box_pass_id;
|
|
|
|
|
+ tcol_cache[k].avail = avail;
|
|
|
|
|
+ tcol_cache[k].maxcols = maxcols;
|
|
|
|
|
+ tcol_cache[k].cols = *out_cols;
|
|
|
|
|
+ tcol_cache[k].total = *out_total;
|
|
|
|
|
+ for (i = 0; i < maxcols; i++)
|
|
|
|
|
+ tcol_cache[k].raw[i] = raw[i];
|
|
|
|
|
+ tcol_cache[k].valid = 1;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
static void layout_table_row(struct lay *l, unsigned int row,
|
|
static void layout_table_row(struct lay *l, unsigned int row,
|
|
|
const struct br_style *pst, int depth,
|
|
const struct br_style *pst, int depth,
|
|
|
unsigned short link)
|
|
unsigned short link)
|