资源描述:
《flash as3 base64》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、FlashAS3Base64网上找到的Base64执行速度都不怎么快,原因是代码对Flash执行机制没有针对性优化。下面给出优化过的Base64,其中inline内联的find方法需要3kis.com的flexsdk补丁才难正常编译。package{importflash.utils.ByteArray;/**优化Base64*主要优化执行方式,尽量减少调用函数和尽可能不使用循环*优化后提升执行速度是原来的10倍*Directedbykiwiw3**/publicclassMyBase64{publicst
2、aticconstversion:String="2.0.0";publicstaticfunctionencode(data:String):String{varbytes:ByteArray=newByteArray();bytes.writeUTFBytes(data);returnencodeByteArray(bytes);}privatestaticconstBASE64_CHARARR:Vector.=new[65,66,67,68,69,70,71,72,73,74,75
3、,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,48,49,50,51,52,53,54,55,56,57,43,47,61];publicstaticfunctionencodeByteArray(data:ByteArray):String{varoutput:
4、ByteArray=newByteArray();varopbuf0:int;varopbuf1:int;varopbuf2:int;varopbuf3:int;vardblen:int=0;varresultlen:uint=data.length;varposition:uint=0;varoplen:uint=0;while(resultlen>0){if(resultlen>=3){dblen=3;resultlen-=3;}else{dblen=resultlen;resultlen=0;}opb
5、uf0=(data[position]&0xfc)>>2;if(dblen>=1)opbuf1=((data[position]&0x03)<<4)
6、((data[position+1])>>4);elseopbuf1=64;if(dblen>=2)opbuf2=((data[position+1]&0x0f)<<2)
7、((data[position+2])>>6);elseopbuf2=64;if(dblen>=3)opbuf3=data[position+2]&0x3f;elseopbuf3=64;ou
8、tput[oplen]=BASE64_CHARARR[opbuf0];output[oplen+1]=BASE64_CHARARR[opbuf1];output[oplen+2]=BASE64_CHARARR[opbuf2];output[oplen+3]=BASE64_CHARARR[opbuf3];position+=3;oplen+=4;}returnoutput.readUTFBytes(oplen);}publicstaticfunctiondecode(data:String):String{v
9、arbytes:ByteArray=decodeToByteArray(data);returnbytes.readUTFBytes(bytes.length);}publicstaticfunctiondecodeToByteArray(_data:String):ByteArray{varoutput:ByteArray=newByteArray();vardata:ByteArray=newByteArray();data.writeUTFBytes(_data);vardatabuf0:int;va
10、rdatabuf1:int;vardatabuf2:int;vardatabuf3:int;varresultlen:uint=data.length;varposition:uint=0;varoplen:uint=0;while(resultlen>0){find(databuf0,data[position]);if(resultlen>=1){find(databuf1,data[position+1])