
Untitled
By: a guest on
May 22nd, 2012 | syntax:
None | size: 1.66 KB | hits: 15 | expires: Never
Optimize ByteArray copy
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;
}
}
}