[SabreAMF] Improvement of SabreAMF_AMF3_Serializer::writeInt

Develar develar at gmail.com
Mon Mar 12 19:48:52 EST 2007


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]);
>         }
>



More information about the sabreamf mailing list