Flex 3 中的 virtual 关键字是否会导致性能下降?
正如标题所说,确实如此。 virtual 关键字是否会导致性能下降?
As the title says really. Does the virtual keyword cause a performance hit?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,在 Actionscript 中,您不需要像在 C# 中那样显式地将要重写的方法标记为虚拟方法,编译器会为您执行此操作。 这就是为什么该关键字不会出现在任何文档中,因为从开发人员的角度来看它是无关紧要的。
不过,要回答您的问题,即重写方法是否会使其变慢,只要您的类是密封的,答案是否定的,这意味着您在定义类时不使用“dynamic”关键字。
原因是,在构造密封类时,您将为该对象的每个方法都有显式标记,当重写方法时,您将直接获得新函数的标记,该类不必查找它运行时就像在动态类中一样。
First off, in Actionscript you don't need to explicitly mark a method to be overridden as virtual as you do in C#, the compiler will do this for you. This is why the keyword doesn't show up in any docs because it is irrelevant from the developers perspective.
To answer your question though, which is whether overriding a method makes it slower, the answer is no as long as your class is sealed, meaning you don't use the 'dynamic' keyword when defining the class.
The reason why is that when constructing a sealed class, you're going to have explicit markers to every method for that object, when overriding a method you get a marker directly to the new function, the class does not have to look it up at runtime like in a dynamic class.
目前 AS3 中所有方法都是虚拟的。 但我的猜测是“虚拟”将在 AS poss 的未来版本中强制执行。 通过一些编译器选项设置。
All methods are virtual in AS3 right now. But my guess is 'virtual' will become enforced in a future version of AS poss. via some compiler option setting.