perf(gen): 结构体按模块查找与 ctypedef 跨度查找加首字节预筛
StructGenMixin.find_struct_by_module 的名与 ModuleSha1 两次 strcmp、TypeGenCType.lookup_ctypedef_span 的逐项名比较,均加首字符/首字节必要条件短路(首字节不等即判不等),并省去原逐项 strlen。匹配结果与返回顺序逐字节不变。
This commit is contained in:
1 parent
16472a61d9
commit
e8db102b9e
2 files changed
+7
-3
No files matched your search
@@ -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 用错误类型短路
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user