as3循环优化
我有这段代码:
palette = new Array(paletteSize);
for (var i:int=0;i<paletteSize;i++) {
palette[i] = 0xFF000000
| (inputStream.readUnsignedByte() << 16)
| (inputStream.readUnsignedByte() << 8)
| (inputStream.readUnsignedByte());
}
这段代码被执行大约 300 次,每次 PaletteSize 的变化范围为 1-255。因此,总的来说,这段代码大约需要 60-80 毫秒。可以通过某种方式优化吗? inputStream(IDataInput) 是一个套接字连接,它不会花费任何时间等待 i/o。仅当流中有足够数量的可用字节时,才会执行此代码。
I have this piece of code:
palette = new Array(paletteSize);
for (var i:int=0;i<paletteSize;i++) {
palette[i] = 0xFF000000
| (inputStream.readUnsignedByte() << 16)
| (inputStream.readUnsignedByte() << 8)
| (inputStream.readUnsignedByte());
}
This code is executed around 300 times and each time paletteSize varies from 1-255. So, on the whole this code takes around 60-80ms. Can this be optimized in some way? inputStream(IDataInput) is a socket connection and it does not spend any time waiting on i/o. This code is only executed when enough number of bytes are available in stream.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
复制自我的评论:尝试使用“矢量”。而不是数组。此外,如果您控制传入流,则可以发送 4 字节颜色并使用 readUnsignedInt 读取它们,从而避免位移。
Copied from my comment: Try use "Vector." instead of Array. Also if you control the incoming stream you could send 4-byte colors and read them using readUnsignedInt instead, avoiding the bit shifting.