refactor(gsub): 去除 subtableAbsPositions 中间数组

优化329 已用 writeInt16At 直接回填,subtableAbsPositions 数组仅为
中间存储起点供回填使用,改为直接用 w.length(allEmpty)/ before(else)
计算相对 lookupStart 偏移。纯重构,输出字节逐字节一致。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
崮生(子虚) 2026-07-25 01:39:10 +08:00
parent 58fc647880
commit baa3a026ed

View File

@ -1442,7 +1442,6 @@ export function subsetGSUB(
w.writeUint16(lookupFlag);
w.writeUint16(lk.subtableAbsOffs.length);
const lookupStart = w.length - 6;
const subtableAbsPositions: number[] = new Array(lk.subtableAbsOffs.length);
/**
* 329 subsetGPOS subtable writeUint16(0) + slot
* writeInt16At reserveOffset16 per-slot + patch push
@ -1460,9 +1459,9 @@ export function subsetGSUB(
* writeEmptySubtable N
* + + rollback subCount lookup */
for (let j = 0; j < lk.subtableAbsOffs.length; j++) {
subtableAbsPositions[j] = w.length;
/** subtable 起点writeEmpty 前)回填到偏移槽(相对 lookupStart */
w.writeInt16At(subtableSlotsStart + j * 2, w.length - lookupStart);
writeEmptySubtable(w, lk.effectiveType);
w.writeInt16At(subtableSlotsStart + j * 2, subtableAbsPositions[j] - lookupStart);
}
} else {
for (let j = 0; j < lk.subtableAbsOffs.length; j++) {
@ -1476,8 +1475,7 @@ export function subsetGSUB(
w.rollback(before);
writeEmptySubtable(w, lk.effectiveType);
}
/** 记录实际 subtable 起点(成功=before失败回退后=before 同值)并回填偏移槽 */
subtableAbsPositions[j] = before;
/** 回填偏移槽subtable 起点为 before成功=serializeSubtable 起点,失败=rollback 后空 subtable 起点,两者同值) */
w.writeInt16At(subtableSlotsStart + j * 2, before - lookupStart);
}
}