最快获得一个物体的方式在AS3值 [英] Fastest way to get an Objects values in as3

查看:207
本文介绍了最快获得一个物体的方式在AS3值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好了,我发誓,这个问题应该是所有的地方,但它不是。

Ok, so I swear this question should be all over the place, but its not.

我有一个值对象,里面有大量的getter / setter方法​​。它不是一个动态类。而我迫切需要寻找充满了他们的ArrayCollection。搜索涵盖所有领域,所以,有大约13不同类型的虚拟组织的,我会用这样做。

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.

我试过ObjectUtil.toString(),并且工作正常,并所有,但它是慢如蜗牛。有20个属性,返回和ObjectUtil.toString()增加了一堆垃圾的产量,更何况code是缓慢的开始。

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()更是雪上加霜。

flash.utils.describeType() is even worse.

我会很高兴听到我缺少明显的东西。

I'll be pleased to hear I'm missing something obvious.

更新: 最后我走胡安的code以及我使用的搜索过滤器算法,创造ArrayCollectionX。这意味着,每一个的ArrayCollection我用现在处理它自己的过滤器。 C时处理像一个冠军全集合搜索,我可以通过搜索的交流项目各个属性,或与胡安的$ C $。相比与外部的过滤器相同的溶液有可忽略不计的延迟。

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.

推荐答案

如果我正确理解你的问题,你想要的是为特定对象定义的干将的列表。据我所知,你将不得不使用不如describeType这样的事情(我pretty的肯定ObjectUtils使用此方法的引擎盖下)。

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).

调用describeType很多将是缓慢的,因为你注意到。但对于只有13种,这不应该是有问题的,我想。由于这些类型是不是动态的,你知道它们的属性是固定的,这样你就可以获取该数据一次,并对其进行缓存。你可以建立自己的高速缓存前面或者你发现新类型。

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.

下面是一个简单的方法来做到这一点在code:

Here's is a simple way to do this in code:

private var typePropertiesCache:Object = {};

private function getPropertyNames(instance:Object):Array {
    var className:String = getQualifiedClassName(instance);
    if(typePropertiesCache[className]) {
        return typePropertiesCache[className];
    }
    var typeDef:XML = describeType(instance);
    var props:Array = [];
    for each(var prop:XML in typeDef.accessor.(@access == "readwrite" || @access == "readonly")) {
        props.push(prop.@name);
    }   
    return typePropertiesCache[className] = props;
}

这篇关于最快获得一个物体的方式在AS3值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆