Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Use faster hashing algorithms when possible #52948

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,6 @@ private function isNamedArguments(Node $arguments): bool

private function getVarName(): string
{
return sprintf('__internal_%s', hash('sha256', uniqid(mt_rand(), true), false));
return sprintf('__internal_%s', hash('xxh128', uniqid(mt_rand(), true)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need a random var name here. A global sequence would be enough to ensure there is no conflict.
Similar to what I did in https://github.com/twigphp/Twig/pull/3601/files#diff-47bc8653b21716576958e25b6d7356ecb0f0070f17554d12d2bee985ac211b26R59

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function initialize(ConsoleCommandEvent $event): void
return;
}

$request->attributes->set('_stopwatch_token', substr(hash('sha256', uniqid(mt_rand(), true)), 0, 6));
$request->attributes->set('_stopwatch_token', substr(hash('xxh128', uniqid(mt_rand(), true)), 0, 6));
$this->stopwatch->openSection();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1693,7 +1693,7 @@ public function testCachePoolServices()
->replaceArgument(0, $expectedSeed)
->replaceArgument(1, 12),
(new ChildDefinition('cache.adapter.redis'))
->replaceArgument(0, new Reference('.cache_connection.kYdiLgf'))
->replaceArgument(0, new Reference('.cache_connection.U5HliuY'))
->replaceArgument(1, $expectedSeed)
->replaceArgument(2, 12),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public function testFirewalls()
[
'simple',
'security.user_checker',
'.security.request_matcher.h5ibf38',
'.security.request_matcher.rud_2nr',
false,
false,
'',
Expand Down Expand Up @@ -187,7 +187,7 @@ public function testFirewalls()
[
'host',
'security.user_checker',
'.security.request_matcher.bcmu4fb',
'.security.request_matcher.ap9sh8g',
true,
false,
'security.user.provider.concrete.default',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public function process(ContainerBuilder $container): void

private function getNamespace(string $seed, string $id): string
{
return substr(str_replace('/', '-', base64_encode(hash('sha256', $id.$seed, true))), 0, 10);
return substr(str_replace('/', '-', base64_encode(hash('xxh128', $id.$seed, true))), 0, 10);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function testNamespaceArgumentIsReplaced()

$this->cachePoolPass->process($container);

$this->assertSame('z3X945Jbf5', $cachePool->getArgument(0));
$this->assertSame('cKLcR15Llk', $cachePool->getArgument(0));
}

public function testNamespaceArgumentIsSeededWithAdapterClassName()
Expand All @@ -70,7 +70,7 @@ public function testNamespaceArgumentIsSeededWithAdapterClassName()

$this->cachePoolPass->process($container);

$this->assertSame('xmOJ8gqF-Y', $cachePool->getArgument(0));
$this->assertSame('mVXLns1cYU', $cachePool->getArgument(0));
}

public function testNamespaceArgumentIsSeededWithAdapterClassNameWithoutAffectingOtherCachePools()
Expand All @@ -97,7 +97,7 @@ public function testNamespaceArgumentIsSeededWithAdapterClassNameWithoutAffectin

$this->cachePoolPass->process($container);

$this->assertSame('xmOJ8gqF-Y', $cachePool->getArgument(0));
$this->assertSame('mVXLns1cYU', $cachePool->getArgument(0));
}

public function testNamespaceArgumentIsNotReplacedIfArrayAdapterIsUsed()
Expand Down Expand Up @@ -153,7 +153,7 @@ public function testArgsAreReplaced()

$this->assertInstanceOf(Reference::class, $cachePool->getArgument(0));
$this->assertSame('foobar', (string) $cachePool->getArgument(0));
$this->assertSame('6Ridbw4aMn', $cachePool->getArgument(1));
$this->assertSame('ZmalVIjCbI', $cachePool->getArgument(1));
$this->assertSame(3, $cachePool->getArgument(2));
}

Expand All @@ -174,7 +174,7 @@ public function testWithNameAttribute()

$this->cachePoolPass->process($container);

$this->assertSame('PeXBWSl6ca', $cachePool->getArgument(1));
$this->assertSame('5SvqAqqNBH', $cachePool->getArgument(1));
}

public function testThrowsExceptionWhenCachePoolTagHasUnknownAttributes()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1592,7 +1592,7 @@ public static function getInitializedConditionals(mixed $value): array
*/
public static function hash(mixed $value): string
{
$hash = substr(base64_encode(hash('sha256', serialize($value), true)), 0, 7);
$hash = substr(base64_encode(hash('xxh128', serialize($value), true)), 0, 7);

return str_replace(['/', '+'], ['.', '_'], $hash);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,6 @@ public function getProxyClass(Definition $definition, bool $asGhostObject, \Refl

return preg_replace('/^.*\\\\/', '', $definition->getClass())
.($asGhostObject ? 'Ghost' : 'Proxy')
.ucfirst(substr(hash('sha256', $this->salt.'+'.$class->name.'+'.serialize($definition->getTag('proxy'))), -7));
.ucfirst(substr(hash('xxh128', $this->salt.'+'.$class->name.'+'.serialize($definition->getTag('proxy'))), -7));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ public static function getSubscribedServices(): array
'autowired' => new ServiceClosureArgument(new TypedReference('service.id', 'stdClass', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, 'autowired', [new Autowire(service: 'service.id')])),
'autowired.nullable' => new ServiceClosureArgument(new TypedReference('service.id', 'stdClass', ContainerInterface::IGNORE_ON_INVALID_REFERENCE, 'autowired.nullable', [new Autowire(service: 'service.id')])),
'autowired.parameter' => new ServiceClosureArgument('foobar'),
'autowire.decorated' => new ServiceClosureArgument(new Reference('.service_locator.oO4rxCy.inner', ContainerInterface::NULL_ON_INVALID_REFERENCE)),
'autowire.decorated' => new ServiceClosureArgument(new Reference('.service_locator.420ES7z.inner', ContainerInterface::NULL_ON_INVALID_REFERENCE)),
'target' => new ServiceClosureArgument(new TypedReference('stdClass', 'stdClass', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, 'target', [new Target('someTarget')])),
];
$this->assertEquals($expected, $container->getDefinition((string) $locator->getFactory()[0])->getArgument(0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ protected static function getFooService($container)
protected static function getFoo2Service($container, $lazyLoad = true)
{
if (true === $lazyLoad) {
return $container->privates['.lazy.Symfony\\Component\\DependencyInjection\\Tests\\Compiler\\Foo'] = $container->createProxy('FooProxy4048957', static fn () => \FooProxy4048957::createLazyProxy(static fn () => self::getFoo2Service($container, false)));
return $container->privates['.lazy.Symfony\\Component\\DependencyInjection\\Tests\\Compiler\\Foo'] = $container->createProxy('FooProxyCd8d23a', static fn () => \FooProxyCd8d23a::createLazyProxy(static fn () => self::getFoo2Service($container, false)));
}

return ($container->services['foo'] ??= new \Symfony\Component\DependencyInjection\Tests\Compiler\Foo());
}
}

class FooProxy4048957 extends \Symfony\Component\DependencyInjection\Tests\Compiler\Foo implements \Symfony\Component\VarExporter\LazyObjectInterface
class FooProxyCd8d23a extends \Symfony\Component\DependencyInjection\Tests\Compiler\Foo implements \Symfony\Component\VarExporter\LazyObjectInterface
{
use \Symfony\Component\VarExporter\LazyProxyTrait;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function isCompiled(): bool
public function getRemovedIds(): array
{
return [
'.lazy.foo.gDmfket' => true,
'.lazy.foo.qFdMZVK' => true,
];
}

Expand All @@ -55,7 +55,7 @@ protected function createProxy($class, \Closure $factory)
*/
protected static function getFooService($container)
{
$a = ($container->privates['.lazy.foo.gDmfket'] ?? self::get_Lazy_Foo_GDmfketService($container));
$a = ($container->privates['.lazy.foo.qFdMZVK'] ?? self::get_Lazy_Foo_QFdMZVKService($container));

if (isset($container->services['foo'])) {
return $container->services['foo'];
Expand All @@ -65,21 +65,21 @@ protected static function getFooService($container)
}

/**
* Gets the private '.lazy.foo.gDmfket' shared service.
* Gets the private '.lazy.foo.qFdMZVK' shared service.
*
* @return \object
*/
protected static function get_Lazy_Foo_GDmfketService($container, $lazyLoad = true)
protected static function get_Lazy_Foo_QFdMZVKService($container, $lazyLoad = true)
{
if (true === $lazyLoad) {
return $container->privates['.lazy.foo.gDmfket'] = $container->createProxy('objectProxy8ac8e9a', static fn () => \objectProxy8ac8e9a::createLazyProxy(static fn () => self::get_Lazy_Foo_GDmfketService($container, false)));
return $container->privates['.lazy.foo.qFdMZVK'] = $container->createProxy('objectProxy1fd6daa', static fn () => \objectProxy1fd6daa::createLazyProxy(static fn () => self::get_Lazy_Foo_QFdMZVKService($container, false)));
}

return ($container->services['foo'] ?? self::getFooService($container));
}
}

class objectProxy8ac8e9a implements \Symfony\Component\DependencyInjection\Tests\Compiler\AInterface, \Symfony\Component\DependencyInjection\Tests\Compiler\IInterface, \Symfony\Component\VarExporter\LazyObjectInterface
class objectProxy1fd6daa implements \Symfony\Component\DependencyInjection\Tests\Compiler\AInterface, \Symfony\Component\DependencyInjection\Tests\Compiler\IInterface, \Symfony\Component\VarExporter\LazyObjectInterface
{
use \Symfony\Component\VarExporter\LazyProxyTrait;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ namespace Container%s;

include_once $container->targetDir.''.'/Fixtures/includes/foo.php';

class FooClassGhostEe53b95 extends \Bar\FooClass implements \Symfony\Component\VarExporter\LazyObjectInterface
class FooClassGhost1728205 extends \Bar\FooClass implements \Symfony\Component\VarExporter\LazyObjectInterface
%A

if (!\class_exists('FooClassGhostEe53b95', false)) {
\class_alias(__NAMESPACE__.'\\FooClassGhostEe53b95', 'FooClassGhostEe53b95', false);
if (!\class_exists('FooClassGhost1728205', false)) {
\class_alias(__NAMESPACE__.'\\FooClassGhost1728205', 'FooClassGhost1728205', false);
}

[Container%s/ProjectServiceContainer.php] => <?php
Expand Down Expand Up @@ -74,7 +74,7 @@ class ProjectServiceContainer extends Container
protected static function getLazyFooService($container, $lazyLoad = true)
{
if (true === $lazyLoad) {
return $container->services['lazy_foo'] = $container->createProxy('FooClassGhostEe53b95', static fn () => \FooClassGhostEe53b95::createLazyGhost(static fn ($proxy) => self::getLazyFooService($container, $proxy)));
return $container->services['lazy_foo'] = $container->createProxy('FooClassGhost1728205', static fn () => \FooClassGhost1728205::createLazyGhost(static fn ($proxy) => self::getLazyFooService($container, $proxy)));
}

include_once $container->targetDir.''.'/Fixtures/includes/foo_lazy.php';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected function createProxy($class, \Closure $factory)
protected static function getBarService($container, $lazyLoad = true)
{
if (true === $lazyLoad) {
return $container->services['bar'] = $container->createProxy('stdClassGhost2fc7938', static fn () => \stdClassGhost2fc7938::createLazyGhost(static fn ($proxy) => self::getBarService($container, $proxy)));
return $container->services['bar'] = $container->createProxy('stdClassGhostAa01f12', static fn () => \stdClassGhostAa01f12::createLazyGhost(static fn ($proxy) => self::getBarService($container, $proxy)));
}

return $lazyLoad;
Expand All @@ -66,7 +66,7 @@ protected static function getBarService($container, $lazyLoad = true)
protected static function getBazService($container, $lazyLoad = true)
{
if (true === $lazyLoad) {
return $container->services['baz'] = $container->createProxy('stdClassProxy2fc7938', static fn () => \stdClassProxy2fc7938::createLazyProxy(static fn () => self::getBazService($container, false)));
return $container->services['baz'] = $container->createProxy('stdClassProxyAa01f12', static fn () => \stdClassProxyAa01f12::createLazyProxy(static fn () => self::getBazService($container, false)));
}

return \foo_bar();
Expand All @@ -80,7 +80,7 @@ protected static function getBazService($container, $lazyLoad = true)
protected static function getBuzService($container, $lazyLoad = true)
{
if (true === $lazyLoad) {
return $container->services['buz'] = $container->createProxy('stdClassProxy2fc7938', static fn () => \stdClassProxy2fc7938::createLazyProxy(static fn () => self::getBuzService($container, false)));
return $container->services['buz'] = $container->createProxy('stdClassProxyAa01f12', static fn () => \stdClassProxyAa01f12::createLazyProxy(static fn () => self::getBuzService($container, false)));
}

return \foo_bar();
Expand All @@ -94,14 +94,14 @@ protected static function getBuzService($container, $lazyLoad = true)
protected static function getFooService($container, $lazyLoad = true)
{
if (true === $lazyLoad) {
return $container->services['foo'] = $container->createProxy('stdClassGhost2fc7938', static fn () => \stdClassGhost2fc7938::createLazyGhost(static fn ($proxy) => self::getFooService($container, $proxy)));
return $container->services['foo'] = $container->createProxy('stdClassGhostAa01f12', static fn () => \stdClassGhostAa01f12::createLazyGhost(static fn ($proxy) => self::getFooService($container, $proxy)));
}

return $lazyLoad;
}
}

class stdClassGhost2fc7938 extends \stdClass implements \Symfony\Component\VarExporter\LazyObjectInterface
class stdClassGhostAa01f12 extends \stdClass implements \Symfony\Component\VarExporter\LazyObjectInterface
{
use \Symfony\Component\VarExporter\LazyGhostTrait;

Expand All @@ -113,7 +113,7 @@ class_exists(\Symfony\Component\VarExporter\Internal\Hydrator::class);
class_exists(\Symfony\Component\VarExporter\Internal\LazyObjectRegistry::class);
class_exists(\Symfony\Component\VarExporter\Internal\LazyObjectState::class);

class stdClassProxy2fc7938 extends \stdClass implements \Symfony\Component\VarExporter\LazyObjectInterface
class stdClassProxyAa01f12 extends \stdClass implements \Symfony\Component\VarExporter\LazyObjectInterface
{
use \Symfony\Component\VarExporter\LazyProxyTrait;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function isCompiled(): bool
public function getRemovedIds(): array
{
return [
'.service_locator.mtT6G8y' => true,
'.service_locator.lViPm9k' => true,
'foo' => true,
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ protected static function getFooService($container, $lazyLoad = true)
$container->factories['service_container']['foo'] ??= self::getFooService(...);

if (true === $lazyLoad) {
return $container->createProxy('stdClassGhost2fc7938', static fn () => \stdClassGhost2fc7938::createLazyGhost(static fn ($proxy) => self::getFooService($container, $proxy)));
return $container->createProxy('stdClassGhostAa01f12', static fn () => \stdClassGhostAa01f12::createLazyGhost(static fn ($proxy) => self::getFooService($container, $proxy)));
}

return $lazyLoad;
}
}

class stdClassGhost2fc7938 extends \stdClass implements \Symfony\Component\VarExporter\LazyObjectInterface
class stdClassGhostAa01f12 extends \stdClass implements \Symfony\Component\VarExporter\LazyObjectInterface
{
use \Symfony\Component\VarExporter\LazyGhostTrait;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected static function getFooService($container, $lazyLoad = true)
$container->factories['foo'] ??= fn () => self::getFooService($container);

if (true === $lazyLoad) {
return $container->createProxy('FooLazyClassGhost2108fce', static fn () => \FooLazyClassGhost2108fce::createLazyGhost(static fn ($proxy) => self::getFooService($container, $proxy)));
return $container->createProxy('FooLazyClassGhost82ad1a4', static fn () => \FooLazyClassGhost82ad1a4::createLazyGhost(static fn ($proxy) => self::getFooService($container, $proxy)));
}

static $include = true;
Expand All @@ -66,7 +66,7 @@ protected static function getFooService($container, $lazyLoad = true)
}
}

class FooLazyClassGhost2108fce extends \Bar\FooLazyClass implements \Symfony\Component\VarExporter\LazyObjectInterface
class FooLazyClassGhost82ad1a4 extends \Bar\FooLazyClass implements \Symfony\Component\VarExporter\LazyObjectInterface
{
use \Symfony\Component\VarExporter\LazyGhostTrait;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function isCompiled(): bool
public function getRemovedIds(): array
{
return [
'.service_locator.PWbaRiJ' => true,
'.service_locator.DyWBOhJ' => true,
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function isCompiled(): bool
public function getRemovedIds(): array
{
return [
'.service_locator.ZP1tNYN' => true,
'.service_locator.X7o4UPP' => true,
'foo2' => true,
'foo3' => true,
'foo4' => true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public function isCompiled(): bool
public function getRemovedIds(): array
{
return [
'.service_locator.2hyyc9y' => true,
'.service_locator.KGUGnmw' => true,
'.service_locator.KGUGnmw.foo_service' => true,
'.service_locator.2x56Fsq' => true,
'.service_locator.2x56Fsq.foo_service' => true,
'.service_locator.K8KBCZO' => true,
'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\CustomDefinition' => true,
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected function createProxy($class, \Closure $factory)
protected static function getWitherService($container, $lazyLoad = true)
{
if (true === $lazyLoad) {
return $container->services['wither'] = $container->createProxy('WitherProxy580fe0f', static fn () => \WitherProxy580fe0f::createLazyProxy(static fn () => self::getWitherService($container, false)));
return $container->services['wither'] = $container->createProxy('WitherProxy1991f2a', static fn () => \WitherProxy1991f2a::createLazyProxy(static fn () => self::getWitherService($container, false)));
}

$instance = new \Symfony\Component\DependencyInjection\Tests\Compiler\Wither();
Expand All @@ -71,7 +71,7 @@ protected static function getWitherService($container, $lazyLoad = true)
}
}

class WitherProxy580fe0f extends \Symfony\Component\DependencyInjection\Tests\Compiler\Wither implements \Symfony\Component\VarExporter\LazyObjectInterface
class WitherProxy1991f2a extends \Symfony\Component\DependencyInjection\Tests\Compiler\Wither implements \Symfony\Component\VarExporter\LazyObjectInterface
{
use \Symfony\Component\VarExporter\LazyProxyTrait;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected static function getWitherService($container, $lazyLoad = true)
$container->factories['wither'] ??= fn () => self::getWitherService($container);

if (true === $lazyLoad) {
return $container->createProxy('WitherProxyDd381be', static fn () => \WitherProxyDd381be::createLazyProxy(static fn () => self::getWitherService($container, false)));
return $container->createProxy('WitherProxyE94fdba', static fn () => \WitherProxyE94fdba::createLazyProxy(static fn () => self::getWitherService($container, false)));
}

$instance = new \Symfony\Component\DependencyInjection\Tests\Compiler\Wither();
Expand All @@ -73,7 +73,7 @@ protected static function getWitherService($container, $lazyLoad = true)
}
}

class WitherProxyDd381be extends \Symfony\Component\DependencyInjection\Tests\Compiler\Wither implements \Symfony\Component\VarExporter\LazyObjectInterface
class WitherProxyE94fdba extends \Symfony\Component\DependencyInjection\Tests\Compiler\Wither implements \Symfony\Component\VarExporter\LazyObjectInterface
{
use \Symfony\Component\VarExporter\LazyProxyTrait;

Expand Down
Loading