在 as3 中获取对象值的最快方法
好吧,我发誓这个问题应该无处不在,但事实并非如此。
我有一个值对象,里面有很多 getter/setter。它不是一个动态类。我迫切需要搜索充满它们的 ArrayCollection。搜索涵盖所有领域,因此我将使用大约 13 种不同类型的 VO。
我尝试过 ObjectUtil.toString() ,效果很好,但速度慢得要命。有 20 个属性需要返回,并且 ObjectUtil.toString() 在输出中添加了一堆垃圾,更不用说代码一开始就很慢。
flash.utils.describeType() 更糟糕。
我会很高兴听到我遗漏了一些明显的东西。
更新: 我最终采用了 Juan 的代码以及用于搜索的过滤算法并创建了 ArrayCollectionX。这意味着我现在使用的每个 ArrayCollection 都处理它自己的过滤器。我可以搜索 AC 中项目的各个属性,或者使用 Juan 的代码,它可以像冠军一样处理完整的集合搜索。与使用外部滤波器的相同解决方案相比,延迟可以忽略不计。
Ok, so I swear this question should be all over the place, but its not.
I have a value object, inside are lots of getters/setters. It is not a dynamic class. And I desperately need to search an ArrayCollection filled with them. The search spans all fields, so and there are about 13 different types of VOs I'll be doing this with.
I've tried ObjectUtil.toString() and that works fine and all but it's slow as hell. There are 20 properties to return and ObjectUtil.toString() adds a bunch of junk to the output, not to mention the code is slow to begin with.
flash.utils.describeType() is even worse.
I'll be pleased to hear I'm missing something obvious.
UPDATE:
I ended up taking Juan's code along with the filter algorithm I use for searching and created ArrayCollectionX. Which means that every ArrayCollection I use now handles it's own filters. I can search through individual properties of the items in the AC, or with Juan's code it handles full collection search like a champ. There was negligible lag compared to the same solution with external filters.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我正确理解你的问题,你想要的是为某些对象定义的吸气剂列表。据我所知,您必须使用describeType来完成类似的事情(我很确定ObjectUtils在幕后使用了这个方法)。
正如您所注意到的,大量调用describeType会很慢。但对于只有 13 种类型,我认为这应该不成问题。由于这些类型不是动态的,因此您知道它们的属性是固定的,因此您可以检索此数据一次并将其缓存。您可以预先构建缓存,也可以在发现新类型时构建缓存。
这是在代码中执行此操作的简单方法:
If I understand your problem correctly, what you want is a list of the getters defined for certain objects. As far as I know, you'll have to use describeType for something like this (I'm pretty sure ObjectUtils uses this method under the hood).
Calling describeType a lot is going to be slow, as you note. But for only 13 types, this shouldn't be problematic, I think. Since these types are not dynamic, you know their properties are fixed, so you can retrieve this data once and cache it. You can build your cache up front or as you find new types.
Here's is a simple way to do this in code: