Files
php-uuid/src/Converter/Number/BigNumberConverter.php
T
Thibaud Fabre 89d91a97eb Remove unnecessary conversions in BigNumberConverter
Using the baseConvert method from BigNumber uses two consecutive convert operations:
  - convertToBase10
  - convertFromBase10

In BigNumberConverters context, we can directly call each specific method to avoid
the conversion overhead.
2015-08-13 17:44:40 +02:00

40 lines
1.1 KiB
PHP

<?php
/**
* This file is part of the ramsey/uuid library
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @copyright Copyright (c) Ben Ramsey <ben@benramsey.com>
* @license http://opensource.org/licenses/MIT MIT
* @link https://benramsey.com/projects/ramsey-uuid/ Documentation
* @link https://packagist.org/packages/ramsey/uuid Packagist
* @link https://github.com/ramsey/uuid GitHub
*/
namespace Ramsey\Uuid\Converter\Number;
use Ramsey\Uuid\Converter\NumberConverterInterface;
class BigNumberConverter implements NumberConverterInterface
{
/**
* @param string $hex
*/
public function fromHex($hex)
{
$number = \Moontoast\Math\BigNumber::convertToBase10($hex, 16);
return new \Moontoast\Math\BigNumber($number);
}
public function toHex($integer)
{
if (!$integer instanceof \Moontoast\Math\BigNumber) {
$integer = new \Moontoast\Math\BigNumber($integer);
}
return \Moontoast\Math\BigNumber::convertFromBase10($integer, 16);
}
}