Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(util/gconv): add struct&field cache to improve performance for struct converting #3

Merged

Conversation

gqcn
Copy link

@gqcn gqcn commented Aug 14, 2024

No description provided.

newFieldInfo.LastFuzzyKey.Store(field.Name)
csi.tagOrFiledNameToFieldInfoMap[tagOrFieldName] = newFieldInfo
if newFieldInfo.IsField {
// TODO 为什么只有isField才添加到fieldConvertInfos
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

因为fieldConvertInfos在最开始时是一个map,这个map在一开始就是根据结构体字段名来添加的
大概结构类似于map[字段名]字段信息,显然不能用字段的tag来当key,
对于重复字段,使用索引来存储即可,可以降低遍历次数

StructField: field,
FieldIndexes: fieldIndexes,
ConvertFunc: csi.genFieldConvertFunc(field.Type.String()),
IsCustomConvert: csi.checkTypeHasCustomConvert(field.Type), // TODO merged to ConvertFunc?
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

应该不能合并吧,map转struct时, 打个比方A->B ,A的类型是不确定的(因为map[string]any),只有一个B类型是确定的

@wln32 wln32 merged commit 0c3a588 into wln32:Improve/cache-gconv-struct Aug 14, 2024
@wln32 wln32 deleted the Improve/cache-gconv-struct branch August 14, 2024 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants