mirror of
https://github.com/2234839/web-font.git
synced 2026-09-04 23:02:27 +08:00
perf(cmap): presetCmap 模式 parse 提前返回跳过 subtable 解析
承接优化315(readWindowsAllCodes 复用 presetCmap),cmap.parse 在 presetCmap 存在时 直接返回 presetCmap,跳过整个 cmap 解析:子表目录扫描 + readSubTable 建 format4._lazySegs /format12._lazyGroups + readWindowsAllCodes 调用。 presetCmap 模式下 subTables 的 _lazySegs/_lazyGroups 不再被 lookupFormat4/12 使用 (readWindowsAllCodes 已跳过),cmap.write/sizeof 用 ttf.cmap 的 keys 重建不依赖 subTables,故 format4/12 subtable 的 header 解析纯粹是无用功。 收益(Font.create best-of,叠加优化315的总收益):千字文思源 -8.4%、初夏纯标点 -6.2%、 FiraCode -5.0%、思源标点 -5.5%。千字文前段 woff2 基准 avg 4.9→3.7ms。6 字体 woff2 sha 逐字节一致,SSIM 全部不变。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
ce893976f1
commit
c6316378f2
@ -257,6 +257,17 @@ function readSubTable(reader, ttf, subTable, cmapOffset) {
|
||||
}
|
||||
|
||||
function parse(reader, ttf) {
|
||||
/**
|
||||
* 优化316: presetCmap 模式下(subset 复用 probeGsubAndCmap 的 codepoint→gid,见 readWindowsAllCodes 优化315),
|
||||
* 直接返回 presetCmap 跳过整个 cmap 解析(目录扫描 + readSubTable 建 format4._lazySegs/format12._lazyGroups +
|
||||
* readWindowsAllCodes 二分)。presetCmap 模式下 subTables 的 _lazySegs/_lazyGroups 不再被 lookupFormat4/12 使用
|
||||
* (readWindowsAllCodes 已跳过),cmap.write/sizeof 用 ttf.cmap 的 keys 重建不依赖 subTables,
|
||||
* 故 format4/12 subtable 的 header 解析纯粹是无用功。presetCmap 由 fontSubset 每次新建({}),单次 create 内只读,引用安全。
|
||||
*/
|
||||
if (ttf.readOptions && ttf.readOptions.presetCmap) {
|
||||
return ttf.readOptions.presetCmap;
|
||||
}
|
||||
|
||||
var tcmap = {};
|
||||
var cmapOffset = this.offset;
|
||||
reader.seek(cmapOffset);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user