[0162] 字体处理性能优化#3448
Open
da-liii wants to merge 12 commits into
Open
Conversation
- 为 resolve 添加带 range 参数的重载 - resolve(string c) 只计算一次 get_unicode_range,然后传给循环中的 resolve - 每个字符减少多次 UTF-8 解码开销 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- 在 unicode.cpp 中添加 unicode_range_cache 缓存 string->string 映射 - 添加 get_utf8_code_cached 缓存 string->int 映射 - 将 smart_font.cpp 中的 get_utf8_code 委托给缓存版本 - 大幅减少 strict_cork_to_utf8 和 decode_from_utf8 的重复调用 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- 缓存 dpi_str 和 sz_str 到局部变量 - 避免在 t1/t2/t3/panic 构造中重复调用 as_string Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- 缓存 vdpi_str 和 hdpi_str 避免重复 as_string - 移除 smart_font/math_smart_font/prog_smart_font 中多余的 normalize_half_multiple_size 调用(smart_font_bis 已做) Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- 将 string r= s 改为 string r 避免每次复制整个字符串 - advance 内部会给 r 重新赋值,初始拷贝是浪费的 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- 缓存 dpi_str 和 attempt_str 到局部变量 - 避免在 extra 构造中重复调用 as_string Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- 在 resolve(string c) 中提前计算 sf 并复用 - 减少 math letter 替换的重复哈希查找 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- 提前计算 is_rubber、starts(c, \"<wide-\")、fn[SUBFONT_MAIN]->supports(c) - 避免在 family_tokens 内层循环中重复执行相同检查 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- 在 resolve(c, range, fam, attempt) 中先检查 fam 是否包含 '=' - 对于不含 '=' 的 fam(大多数情况)跳过 tokenize 开销 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
移除验证优化效果时添加的临时调试输出,保持代码整洁。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- test_resolve_performance → test_resolve_mixed_chars(该测试验证正确性而非性能) - 移除 find_font.cpp 和 font_translate.cpp 中解释显而易见代码的注释 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
摘要
对字体处理代码做实验性质的性能优化,共 11 个 commit。
优化内容
get_unicode_range(c)提取到循环外,只计算一次sz_str和dpi_strvdpi_str/hdpi_str,移除多余normalizeget_extents/get_xpositions/draw_fixed中string r= s改为string rdpi_str和attempt_stris_rubber/starts(c, "<wide-")移出循环=的 fam 执行无意义trimmed_tokenize测试
xmake b smart_font_test && xmake r smart_font_test— 12 个测试全部通过xmake b font_size_test && xmake r font_size_test— 19 个测试全部通过🤖 Generated with Claude Code