2011-11-14 10 views
0

以下は、着信バイトストリームを(ByteArray.inflateを使用して)解凍するflashlight-VNCライブラリのコードスニペットです。ByteArrayコピーを最適化する

package com.flashlight.zlib 
{ 

    import com.flashlight.utils.TimeTracker; 

    import flash.utils.ByteArray; 

    import mx.logging.ILogger; 
    import mx.logging.Log; 

    public class Inflater { 
     private var lastDeflate:ByteArray; 

     public function uncompress(compressedData:ByteArray):ByteArray { 
      var uncompressedData:ByteArray = new ByteArray(); 
      var dataOffset:int = lastDeflate ? 0 : 2; 

      TimeTracker.startTimer("TightEncoding[CopyCompresion]"); 
      if (lastDeflate) { 
       var dictionarySize:int = lastDeflate.length > 32768 ? 32768 : lastDeflate.length; 
       uncompressedData.writeByte(0x00); 
       uncompressedData.writeByte(dictionarySize); 
       uncompressedData.writeByte(dictionarySize >> 8); 
       uncompressedData.writeByte(~dictionarySize); 
       uncompressedData.writeByte((~dictionarySize) >> 8); 
       uncompressedData.writeBytes(lastDeflate,lastDeflate.length - dictionarySize, dictionarySize); 
      } 
      uncompressedData.writeBytes(compressedData,dataOffset,compressedData.length-dataOffset); 
      TimeTracker.stopTimer("TightEncoding[CopyCompresion]"); 
      uncompressedData.writeByte(0x01); 
      uncompressedData.writeUnsignedInt(0x0000FFFF); 

      TimeTracker.startTimer("TightEncoding[Realdecompress]"); 
      uncompressedData.inflate(); 
      TimeTracker.stopTimer("TightEncoding[Realdecompress]"); 

      lastDeflate = uncompressedData; 
      uncompressedData.position = dictionarySize; 

      return uncompressedData; 
     } 

    } 
} 

サーバからの圧縮データの一定のストリームがあります。これはInflaterクラスによってブロックごとに拡張されています。 inflate()とwriteBytes()メソッドは一緒にこのクラスの99%の時間を費やします。 inflate()はすでにネイティブコールです。

writeBytesの呼び出しを最適化するにはどうすればよいですか?私たちはそれをスキップして、このコードを他の方法で再配線したり、ByteArrayのコピーを行う最適な方法がありますか?

答えて

0

ByteArrayがネイティブFlashクラスである限り、最適化できるかどうかは不明です。おそらく、FluorineやAlchemyのようなサードパーティライブラリ/フレームワークを使って、C++アルゴリズムを呼び出すことができます。

+0

私はそれを試しましたが、CPUの広範囲な "for"ループがありましたが、bytearrayを渡すのにはかなりの時間がかかります:( – Nakul

+0

ByteArrayのパフォーマンスを向上させるためにhaxe/azothを探しています。 – Nakul