From e8db102b9eb409e96b1b641f1cd7b2d75dca6655 Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Mon, 14 Sep 2026 00:09:06 +0800 Subject: [PATCH] =?UTF-8?q?perf(gen):=20=E7=BB=93=E6=9E=84=E4=BD=93?= =?UTF-8?q?=E6=8C=89=E6=A8=A1=E5=9D=97=E6=9F=A5=E6=89=BE=E4=B8=8E=20ctyped?= =?UTF-8?q?ef=20=E8=B7=A8=E5=BA=A6=E6=9F=A5=E6=89=BE=E5=8A=A0=E9=A6=96?= =?UTF-8?q?=E5=AD=97=E8=8A=82=E9=A2=84=E7=AD=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit StructGenMixin.find_struct_by_module 的名与 ModuleSha1 两次 strcmp、TypeGenCType.lookup_ctypedef_span 的逐项名比较,均加首字符/首字节必要条件短路(首字节不等即判不等),并省去原逐项 strlen。匹配结果与返回顺序逐字节不变。 --- App/lib/core/Gen/StructGenMixin.vp | 6 ++++-- App/lib/core/Gen/Type/TypeGenCType.vp | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/App/lib/core/Gen/StructGenMixin.vp b/App/lib/core/Gen/StructGenMixin.vp index 349d457..32eb114 100644 --- a/App/lib/core/Gen/StructGenMixin.vp +++ b/App/lib/core/Gen/StructGenMixin.vp @@ -893,9 +893,11 @@ class StructGenMixin: for i in range(start, self.StructCount): entry: GenTypes.StructEntry | t.CPtr = self._get_struct_entry(i) if entry is not None and entry.Name is not None: - if string.strcmp(entry.Name, name) == 0: + # 快速路径:strcmp 判等蕴含首字符相等,首字符不同者跳过 strcmp。 + if entry.Name[0] == name[0] and string.strcmp(entry.Name, name) == 0: if entry.ModuleSha1 is not None: - if string.strcmp(entry.ModuleSha1, sha1) == 0: + # 同上:sha1 判等蕴含首字符相等,先比首字符再 strcmp。 + if entry.ModuleSha1[0] == sha1[0] and string.strcmp(entry.ModuleSha1, sha1) == 0: return entry # SHA1 查找失败:不回退到 find_struct(会返回跨模块同名错误 entry) # 返回 None 让调用方创建新类型,避免 Phase B 用错误类型短路 diff --git a/App/lib/core/Gen/Type/TypeGenCType.vp b/App/lib/core/Gen/Type/TypeGenCType.vp index 9130d46..96b7469 100644 --- a/App/lib/core/Gen/Type/TypeGenCType.vp +++ b/App/lib/core/Gen/Type/TypeGenCType.vp @@ -148,7 +148,9 @@ class TypeGenCType(TypeGenBase.TypeGenBase): nm: str = self.CTypedefNames.get(i) if nm is None: continue - if string.strlen(nm) != want: + # 快速路径:命中要求 nm[0]==text[start](逐字节比较的 k=0 项), + # 首字节不同者无需 strlen 即可判定不命中(不影响任何原命中项)。 + if nm[0] != text[start] or string.strlen(nm) != want: continue hit: int = 1 k: sizet = 0