Skip to content

Commit b96f361

Browse files
javiereguiluzfabpot
authored andcommitted
Use faster hashing algorithms when possible
1 parent b735b04 commit b96f361

15 files changed

+35
-35
lines changed

ContainerBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1592,7 +1592,7 @@ public static function getInitializedConditionals(mixed $value): array
15921592
*/
15931593
public static function hash(mixed $value): string
15941594
{
1595-
$hash = substr(base64_encode(hash('sha256', serialize($value), true)), 0, 7);
1595+
$hash = substr(base64_encode(hash('xxh128', serialize($value), true)), 0, 7);
15961596

15971597
return str_replace(['/', '+'], ['.', '_'], $hash);
15981598
}

LazyProxy/PhpDumper/LazyServiceDumper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,6 @@ public function getProxyClass(Definition $definition, bool $asGhostObject, \Refl
146146

147147
return preg_replace('/^.*\\\\/', '', $definition->getClass())
148148
.($asGhostObject ? 'Ghost' : 'Proxy')
149-
.ucfirst(substr(hash('sha256', $this->salt.'+'.$class->name.'+'.serialize($definition->getTag('proxy'))), -7));
149+
.ucfirst(substr(hash('xxh128', $this->salt.'+'.$class->name.'+'.serialize($definition->getTag('proxy'))), -7));
150150
}
151151
}

Tests/Compiler/RegisterServiceSubscribersPassTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ public static function getSubscribedServices(): array
462462
'autowired' => new ServiceClosureArgument(new TypedReference('service.id', 'stdClass', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, 'autowired', [new Autowire(service: 'service.id')])),
463463
'autowired.nullable' => new ServiceClosureArgument(new TypedReference('service.id', 'stdClass', ContainerInterface::IGNORE_ON_INVALID_REFERENCE, 'autowired.nullable', [new Autowire(service: 'service.id')])),
464464
'autowired.parameter' => new ServiceClosureArgument('foobar'),
465-
'autowire.decorated' => new ServiceClosureArgument(new Reference('.service_locator.oO4rxCy.inner', ContainerInterface::NULL_ON_INVALID_REFERENCE)),
465+
'autowire.decorated' => new ServiceClosureArgument(new Reference('.service_locator.420ES7z.inner', ContainerInterface::NULL_ON_INVALID_REFERENCE)),
466466
'target' => new ServiceClosureArgument(new TypedReference('stdClass', 'stdClass', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, 'target', [new Target('someTarget')])),
467467
];
468468
$this->assertEquals($expected, $container->getDefinition((string) $locator->getFactory()[0])->getArgument(0));

Tests/Fixtures/php/lazy_autowire_attribute.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,14 @@ protected static function getFooService($container)
7878
protected static function getFoo2Service($container, $lazyLoad = true)
7979
{
8080
if (true === $lazyLoad) {
81-
return $container->privates['.lazy.Symfony\\Component\\DependencyInjection\\Tests\\Compiler\\Foo'] = $container->createProxy('FooProxy4048957', static fn () => \FooProxy4048957::createLazyProxy(static fn () => self::getFoo2Service($container, false)));
81+
return $container->privates['.lazy.Symfony\\Component\\DependencyInjection\\Tests\\Compiler\\Foo'] = $container->createProxy('FooProxyCd8d23a', static fn () => \FooProxyCd8d23a::createLazyProxy(static fn () => self::getFoo2Service($container, false)));
8282
}
8383

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

88-
class FooProxy4048957 extends \Symfony\Component\DependencyInjection\Tests\Compiler\Foo implements \Symfony\Component\VarExporter\LazyObjectInterface
88+
class FooProxyCd8d23a extends \Symfony\Component\DependencyInjection\Tests\Compiler\Foo implements \Symfony\Component\VarExporter\LazyObjectInterface
8989
{
9090
use \Symfony\Component\VarExporter\LazyProxyTrait;
9191

Tests/Fixtures/php/lazy_autowire_attribute_with_intersection.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function isCompiled(): bool
3939
public function getRemovedIds(): array
4040
{
4141
return [
42-
'.lazy.foo.gDmfket' => true,
42+
'.lazy.foo.qFdMZVK' => true,
4343
];
4444
}
4545

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

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

6767
/**
68-
* Gets the private '.lazy.foo.gDmfket' shared service.
68+
* Gets the private '.lazy.foo.qFdMZVK' shared service.
6969
*
7070
* @return \object
7171
*/
72-
protected static function get_Lazy_Foo_GDmfketService($container, $lazyLoad = true)
72+
protected static function get_Lazy_Foo_QFdMZVKService($container, $lazyLoad = true)
7373
{
7474
if (true === $lazyLoad) {
75-
return $container->privates['.lazy.foo.gDmfket'] = $container->createProxy('objectProxy8ac8e9a', static fn () => \objectProxy8ac8e9a::createLazyProxy(static fn () => self::get_Lazy_Foo_GDmfketService($container, false)));
75+
return $container->privates['.lazy.foo.qFdMZVK'] = $container->createProxy('objectProxy1fd6daa', static fn () => \objectProxy1fd6daa::createLazyProxy(static fn () => self::get_Lazy_Foo_QFdMZVKService($container, false)));
7676
}
7777

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

82-
class objectProxy8ac8e9a implements \Symfony\Component\DependencyInjection\Tests\Compiler\AInterface, \Symfony\Component\DependencyInjection\Tests\Compiler\IInterface, \Symfony\Component\VarExporter\LazyObjectInterface
82+
class objectProxy1fd6daa implements \Symfony\Component\DependencyInjection\Tests\Compiler\AInterface, \Symfony\Component\DependencyInjection\Tests\Compiler\IInterface, \Symfony\Component\VarExporter\LazyObjectInterface
8383
{
8484
use \Symfony\Component\VarExporter\LazyProxyTrait;
8585

Tests/Fixtures/php/services9_lazy_inlined_factories.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ namespace Container%s;
66

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

9-
class FooClassGhostEe53b95 extends \Bar\FooClass implements \Symfony\Component\VarExporter\LazyObjectInterface
9+
class FooClassGhost1728205 extends \Bar\FooClass implements \Symfony\Component\VarExporter\LazyObjectInterface
1010
%A
1111

12-
if (!\class_exists('FooClassGhostEe53b95', false)) {
13-
\class_alias(__NAMESPACE__.'\\FooClassGhostEe53b95', 'FooClassGhostEe53b95', false);
12+
if (!\class_exists('FooClassGhost1728205', false)) {
13+
\class_alias(__NAMESPACE__.'\\FooClassGhost1728205', 'FooClassGhost1728205', false);
1414
}
1515

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

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

Tests/Fixtures/php/services_dedup_lazy.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ protected function createProxy($class, \Closure $factory)
5252
protected static function getBarService($container, $lazyLoad = true)
5353
{
5454
if (true === $lazyLoad) {
55-
return $container->services['bar'] = $container->createProxy('stdClassGhost2fc7938', static fn () => \stdClassGhost2fc7938::createLazyGhost(static fn ($proxy) => self::getBarService($container, $proxy)));
55+
return $container->services['bar'] = $container->createProxy('stdClassGhostAa01f12', static fn () => \stdClassGhostAa01f12::createLazyGhost(static fn ($proxy) => self::getBarService($container, $proxy)));
5656
}
5757

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

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

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

100100
return $lazyLoad;
101101
}
102102
}
103103

104-
class stdClassGhost2fc7938 extends \stdClass implements \Symfony\Component\VarExporter\LazyObjectInterface
104+
class stdClassGhostAa01f12 extends \stdClass implements \Symfony\Component\VarExporter\LazyObjectInterface
105105
{
106106
use \Symfony\Component\VarExporter\LazyGhostTrait;
107107

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

116-
class stdClassProxy2fc7938 extends \stdClass implements \Symfony\Component\VarExporter\LazyObjectInterface
116+
class stdClassProxyAa01f12 extends \stdClass implements \Symfony\Component\VarExporter\LazyObjectInterface
117117
{
118118
use \Symfony\Component\VarExporter\LazyProxyTrait;
119119

Tests/Fixtures/php/services_non_shared_duplicates.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function isCompiled(): bool
4141
public function getRemovedIds(): array
4242
{
4343
return [
44-
'.service_locator.mtT6G8y' => true,
44+
'.service_locator.lViPm9k' => true,
4545
'foo' => true,
4646
];
4747
}

Tests/Fixtures/php/services_non_shared_lazy_ghost.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,14 @@ protected static function getFooService($container, $lazyLoad = true)
6868
$container->factories['service_container']['foo'] ??= self::getFooService(...);
6969

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

7474
return $lazyLoad;
7575
}
7676
}
7777

78-
class stdClassGhost2fc7938 extends \stdClass implements \Symfony\Component\VarExporter\LazyObjectInterface
78+
class stdClassGhostAa01f12 extends \stdClass implements \Symfony\Component\VarExporter\LazyObjectInterface
7979
{
8080
use \Symfony\Component\VarExporter\LazyGhostTrait;
8181

Tests/Fixtures/php/services_non_shared_lazy_public.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ protected static function getFooService($container, $lazyLoad = true)
5151
$container->factories['foo'] ??= fn () => self::getFooService($container);
5252

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

5757
static $include = true;
@@ -66,7 +66,7 @@ protected static function getFooService($container, $lazyLoad = true)
6666
}
6767
}
6868

69-
class FooLazyClassGhost2108fce extends \Bar\FooLazyClass implements \Symfony\Component\VarExporter\LazyObjectInterface
69+
class FooLazyClassGhost82ad1a4 extends \Bar\FooLazyClass implements \Symfony\Component\VarExporter\LazyObjectInterface
7070
{
7171
use \Symfony\Component\VarExporter\LazyGhostTrait;
7272

0 commit comments

Comments
 (0)