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

关于testCustom增加部分json导致其测试失败问题 #112

Closed
tripleCC opened this issue Jun 2, 2016 · 6 comments
Closed

关于testCustom增加部分json导致其测试失败问题 #112

tripleCC opened this issue Jun 2, 2016 · 6 comments

Comments

@tripleCC
Copy link

tripleCC commented Jun 2, 2016

修改 testCustom方法中的
json = @"{\".ext\":\"Apple\"}";

json = @"{\".ext\":\"Apple\", \"name\":\"Apple\", \"count\":\"10\", \"desc1\":\"Apple\", \"desc2\":\"Apple\", \"desc3\":\"Apple\", \"desc4\":\"Apple\", \"modelID\":\"Apple\"

这样执行yy_modelSetWithDictionary的时候,因为modelMeta->_keyMappedCount=8, CFDictionaryGetCount((CFDictionaryRef)dic))=7,所以不会执行第一个if分支中的

CFDictionaryApplyFunction((CFDictionaryRef)dic, ModelSetWithDictionaryFunction, &context);
而是执行if的else分支
CFArrayApplyFunction((CFArrayRef)modelMeta->_allPropertyMetas, CFRangeMake(0, modelMeta->_keyMappedCount), ModelSetWithPropertyMetaArrayFunction, &context);
在回调函数中ModelSetWithPropertyMetaArrayFunction中,想利用YYValueForKeyPath获取@{@".ext" : @"Apple"}的值,其结果是失败的。

虽然我不是很明白modelMeta->_keyMappedCount >= CFDictionaryGetCount((CFDictionaryRef)dic)这个if分支的带来的好处(感觉即使只有第二个分支,除了testCustom出现以上的错误外,其他测试都能过,不过可能也有性能方面的考虑吧),但是在我说的上面那种情况下,测试结果的确是失败的。不知道这种情况是不是正常的呢?

@ibireme
Copy link
Owner

ibireme commented Jun 2, 2016

感谢提出问题,这里是在处理特殊的 key path (例如 ".ext" "a..b" "a.b.." ) 不够完善,已修复:c53f3bb

@tripleCC tripleCC closed this as completed Jun 3, 2016
@tripleCC tripleCC reopened this Jun 3, 2016
@tripleCC
Copy link
Author

tripleCC commented Jun 3, 2016

我今天又针对yy_modelSetWithDictionary方法中的
if (modelMeta->_keyMappedCount >= CFDictionaryGetCount((CFDictionaryRef)dic))
分支是否冗余做了下测试。
在去掉其中任何一个分支的情况下,运行了单元测试以及ModelBenchmark工程。结果是在效率上似乎没有什么区别,也都能够正确运行。
感觉第一个分支只是把第二个分支分三种类型分开处理了,其本质都是调用ModelSetValueForProperty设置的属性值,并且实际上取两个分支中的任何一个分支,其调用ModelSetValueForProperty的频率也是一致的。
只不过在第一个分支中针对映射到相同key的情况,可以利用_YYModelPropertyMeta的_next,只取一次字典的value,而第二个分支需要每个属性都取一次。
我还是想知道这个if判断分支的实际作用,但是自己还是难以理解。
希望作者能够帮忙点拨下我的疑惑。。。

@ibireme
Copy link
Owner

ibireme commented Jun 3, 2016

只是能尽量减少外面的遍历次数,但这个其实优化空间是很有限的。

@tripleCC tripleCC closed this as completed Jun 3, 2016
@molon
Copy link

molon commented Jun 3, 2016

@ibireme 或许遇到在通过[xxx componentsSeparatedByString:@"."]分解之后如果发现有空的应该就直接认为xxx是不具有层级关系的,直接使用..ext.xxx..类似这样的作为key,这样处理可能好些。(但是倘若有需求是a.b,但是又想其不具有层级关系这样的需求还是没办法,真的不得不吐槽设计这样的key很古怪啊)
而且不但需要处理mappedToKeyNSString的情况,其为NSArray的情况也需要处理。

@tripleCC
Copy link
Author

tripleCC commented Jun 3, 2016

@molon 我也是没见过@".etx"这样的key...

@ibireme
Copy link
Owner

ibireme commented Jun 3, 2016

如果真有这种 key 那还挺头疼的。。正向反向转换都不太好处理。。

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

No branches or pull requests

3 participants