[SabreAMF] Improvement of SabreAMF_AMF3_Serializer::writeInt
Evert | Rooftop
evert at rooftopsolutions.nl
Mon Mar 12 23:48:51 EST 2007
Very very cool !
code is on subversion.. Will test it this weekend, but looks good to me..
Evert
Develar wrote:
> unset is not necessary
>
> public function writeInt($int)
> {
> $bytes = array();
> if (($int & 0xff000000) == 0)
> {
> for ($i = 3; $i > -1; $i--)
> {
> $bytes[] = ($int >> (7 * $i)) & 0x7F;
> }
> }
> else
> {
> for ($i = 2; $i > -1; $i--)
> {
> $bytes[] = ($int >> (8 + 7 * $i)) & 0x7F;
> }
> $bytes[] = $int & 0xFF;
> }
>
> for ($i = 0; $i < 3; $i++)
> {
> if ($bytes[$i] > 0)
> {
> $this->stream->writeByte($bytes[$i] | 0x80);
> }
> }
> $this->stream->writeByte($bytes[3]);
> }
>
>
> 2007/3/13, Develar <develar at gmail.com>:
>
>> 1000 iterations, 0.018 vs 0.0827
>>
>> public function writeInt($int)
>> {
>> $bytes = array();
>> if (($int & 0xff000000) == 0)
>> {
>> for ($i = 3; $i > -1; $i--)
>> {
>> $bytes[] = ($int >> (7 * $i)) & 0x7F;
>> }
>> }
>> else
>> {
>> for ($i = 2; $i > -1; $i--)
>> {
>> $bytes[] = ($int >> (8 + 7 * $i)) & 0x7F;
>> }
>> $bytes[] = $int & 0xFF;
>> }
>>
>> for ($i = 0; $i < 3; $i++)
>> {
>> if ($bytes[$i] == 0)
>> {
>> unset($bytes[$i]);
>> }
>> else
>> {
>> $this->stream->writeByte($bytes[$i] | 0x80);
>> }
>> }
>> $this->stream->writeByte($bytes[3]);
>> }
>>
>>
>
> _______________________________________________
> sabreamf mailing list
> sabreamf at osflash.org
> http://osflash.org/mailman/listinfo/sabreamf_osflash.org
>
>
More information about the sabreamf
mailing list