Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 22nd, 2012  |  syntax: None  |  size: 1.66 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Optimize ByteArray copy
  2. package com.flashlight.zlib
  3. {
  4.  
  5.     import com.flashlight.utils.TimeTracker;
  6.  
  7.     import flash.utils.ByteArray;
  8.  
  9.     import mx.logging.ILogger;
  10.     import mx.logging.Log;
  11.  
  12.     public class Inflater {
  13.         private var lastDeflate:ByteArray;
  14.  
  15.         public function uncompress(compressedData:ByteArray):ByteArray {
  16.             var uncompressedData:ByteArray = new ByteArray();
  17.             var dataOffset:int = lastDeflate ? 0 : 2;
  18.  
  19.             TimeTracker.startTimer("TightEncoding[CopyCompresion]");
  20.             if (lastDeflate) {
  21.                 var dictionarySize:int = lastDeflate.length > 32768 ? 32768 : lastDeflate.length;
  22.                 uncompressedData.writeByte(0x00);
  23.                 uncompressedData.writeByte(dictionarySize );
  24.                 uncompressedData.writeByte(dictionarySize >> 8);
  25.                 uncompressedData.writeByte(~dictionarySize);
  26.                 uncompressedData.writeByte((~dictionarySize) >> 8 );
  27.                 uncompressedData.writeBytes(lastDeflate,lastDeflate.length - dictionarySize, dictionarySize);
  28.             }
  29.             uncompressedData.writeBytes(compressedData,dataOffset,compressedData.length-dataOffset);
  30.             TimeTracker.stopTimer("TightEncoding[CopyCompresion]");
  31.             uncompressedData.writeByte(0x01);
  32.             uncompressedData.writeUnsignedInt(0x0000FFFF);
  33.  
  34.             TimeTracker.startTimer("TightEncoding[Realdecompress]");
  35.             uncompressedData.inflate();
  36.             TimeTracker.stopTimer("TightEncoding[Realdecompress]");
  37.  
  38.             lastDeflate = uncompressedData;
  39.             uncompressedData.position = dictionarySize;
  40.  
  41.             return uncompressedData;
  42.         }
  43.  
  44.     }
  45. }