ActionScript 3.0中最好的选择子类Vector类(Flash播放器10)最好的、子类、播放器、ActionScript

2023-09-08 11:27:50 作者:跟紧步伐

我想利用的新载体类FP10的所有善良的优势,但现在看来,这被标记为最终决定。

I would like to take advantage of all the goodness of the newer Vector class for FP10, but it seems it is marked as final.

我做了一些密集的数学处理在ActionScript中,反反复复的过程数字阵列。我有previously一直在使用自己的阵列的子类(我称之为 NumericArray ),具有附加功能,如SUM(),是指(),加()乘()等,这工作得很好,并允许一些干净的OO code。不过,我通过分析发现,约95%的我的处理时间在这些对象的功能出现。我需要更多的表现出这些阵列。

I am doing some intensive mathematical processing in Actionscript, and repeatedly process arrays of Numbers. I have previously been using my own subclass of Array(I call it NumericArray), with added functions such as sum(), mean(), add(), multiply(), etc. This works very well and allows for some clean OO code. However, I am finding through profiling that about 95% of my processing time occurs in the functions of these objects. I need more performance out of these arrays.

我想用一个矢量,因为它提供了一些性能增强。我想专门使用一个矢量<数> 。不幸的是,我不能继承载体,因为它标记为final。

I want to use a Vector, as it provides some performance enhancements. I want to specifically use a Vector.<Number>. Unfortunately, I cannot subclass Vector as it is marked final.

什么是模仿我与阵列的一个子类previously做,到矢量最好的和干净的方式&LT;编号&GT;

What is the best and cleanest way to imitate what I was previously doing with a subclass of Array, to a Vector.<Number>?

我曾想过身边掠过矢量&lt;数量&GT; 变量,而不是我的自定义类,只是使用的实用功能来操作,但是这是不好的面向对象设计,将是一个痛苦的使用,更不要说难看。

I have thought about passing around Vector.<Number> variables instead of my custom class and just using utility functions to manipulate, but this is not good OO design and will be a pain to use, not to mention ugly.

推荐答案

如果您添加额外的功能,并不需要访问受保护的属性/向量的方法,你可以创建一个包装类的载体。这些方针的东西?

If adding your additional functionality doesn't require access to protected properties/methods of Vector, you could create a wrapper class for the Vector. Something along these lines?

import flash.utils.Proxy;
import flash.utils.flash_proxy;

use namespace flash_proxy;

public class NumericVector extends Proxy
{
     private var vector:Vector.<Number>;

     public function NumericVector(vector:Vector.<Number> = null)
     {
          if(vector == null)
          {
              this.vector = new Vector.<Number>();
          }
          else
          {
              this.vector = vector;
          }
     }

     override flash_proxy function nextName(index:int):String 
     {
         return vector[index - 1].toString();
     }

     override flash_proxy function nextNameIndex(index:int):int
     {
         // implementation
     }

     public function sum():Number
     {
         // do whatever you intend to do
     }

     ...
}
 
精彩推荐
图片推荐