Skip to content

Commit

Permalink
remove mark.isItemEnd (long-standing TODO)
Browse files Browse the repository at this point in the history
should be better for perf (stops less frequently for paragraphs
that use fallback fonts) and removes state from createLineboxes
which is about to get more complicated for break-word
  • Loading branch information
chearon committed Apr 7, 2024
1 parent e6ab12c commit 62b6744
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions src/layout-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1559,7 +1559,6 @@ interface IfcMark {
isBreak: boolean,
isBreakForced: boolean,
isItemStart: boolean,
isItemEnd: boolean,
inlinePre: Inline | null,
inlinePost: Inline | null,
block: BlockContainer | null,
Expand Down Expand Up @@ -1978,7 +1977,6 @@ export class Paragraph {
let breakMark = 0;
// Item iterator
let itemIndex = -1;
let emittedItemEnd = false;
let itemMeasureState: MeasureState | undefined;
let itemMark = 0;
// Other
Expand All @@ -1990,7 +1988,6 @@ export class Paragraph {
isBreak: false,
isBreakForced: false,
isItemStart: false,
isItemEnd: false,
inlinePre: null,
inlinePost: null,
block: null,
Expand All @@ -2011,11 +2008,6 @@ export class Paragraph {
mark.trailingWs = trailingWs;
}

if (itemIndex < this.brokenItems.length && itemMark === mark.position && !emittedItemEnd) {
mark.isItemEnd = itemIndex > -1;
emittedItemEnd = true;
}

// Consume the inline break spot if we're not on a break
if (!inline.done && inline.value.state === 'breakspot' && inlineMark === mark.position && (breakMark === 0 || breakMark !== mark.position)) {
inline = inlineIterator.next();
Expand Down Expand Up @@ -2075,7 +2067,6 @@ export class Paragraph {
itemMeasureState = item.createMeasureState();
mark.isItemStart = true;
mark.itemIndex += 1;
emittedItemEnd = false;
}
}

Expand Down Expand Up @@ -2137,7 +2128,6 @@ export class Paragraph {
const lines = [];
let floats = [];
let blockOffset = bfc.cbBlockStart;
let itemInMark: ShapedItem | undefined; // TODO: merge with item?

// Optimization: here we assume that (1) doTextLayout will never be called
// on the same ifc with a 'normal' mode twice and (2) that when the mode is
Expand Down Expand Up @@ -2165,11 +2155,11 @@ export class Paragraph {
const parent = parents[parents.length - 1] || this.ifc;
const item = this.brokenItems[mark.itemIndex];

if (mark.isItemEnd) itemInMark = undefined;

if (mark.inlinePre) {
candidates.height.pushInline(mark.inlinePre);
if (itemInMark) candidates.height.stampMetrics(getMetrics(mark.inlinePre.style, itemInMark.match));
if (item && item.offset <= mark.inlinePre.start && item.end() > mark.inlinePre.start) {
candidates.height.stampMetrics(getMetrics(mark.inlinePre.style, item.match));
}
parents.push(mark.inlinePre);
}

Expand Down Expand Up @@ -2305,8 +2295,7 @@ export class Paragraph {
item.inlines = parents.slice();
for (const p of parents) p.nshaped += 1;
candidates.push(item);
itemInMark = item;
candidates.height.stampMetrics(getMetrics(parent.style, itemInMark.match));
candidates.height.stampMetrics(getMetrics(parent.style, item.match));
}

// Handle a span that starts inside a shaped item
Expand Down

0 comments on commit 62b6744

Please sign in to comment.