8000 minor #59355 Use `spl_object_id()` instead of `spl_object_hash()` (ro… · symfony/symfony@31df2cf · GitHub
[go: up one dir, main page]

Skip to content

Commit 31df2cf

Browse files
minor #59355 Use spl_object_id() instead of spl_object_hash() (rosier)
This PR was merged into the 7.3 branch. Discussion ---------- Use `spl_object_id()` instead of `spl_object_hash()` | Q | A | ------------- | --- | Branch? | 7.3 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | - | License | MIT Small performance tweak. Commits ------- b717570 Use spl_object_id() instead of spl_object_hash()
2 parents 1ea7204 + b717570 commit 31df2cf

File tree

4 files changed

8000 +24
-24
lines changed

4 files changed

+24
-24
lines changed

src/Symfony/Component/HttpKernel/DataCollector/LoggerDataCollector.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,10 @@ private function sanitizeLogs(array $logs): array
233233
$exception = $log['context']['exception'];
234234

235235
if ($exception instanceof SilencedErrorContext) {
236-
if (isset($silencedLogs[$h = spl_object_hash($exception)])) {
236+
if (isset($silencedLogs[$id = spl_object_id($exception)])) {
237237
continue;
238238
}
239-
$silencedLogs[$h] = true;
239+
$silencedLogs[$id] = true;
240240

241241
if (!isset($sanitizedLogs[$message])) {
242242
$sanitizedLogs[$message] = $log + [
@@ -312,10 +312,10 @@ private function computeErrorsCount(array $containerDeprecationLogs): array
312312
if ($this->isSilencedOrDeprecationErrorLog($log)) {
313313
$exception = $log['context']['exception'];
314314
if ($exception instanceof SilencedErrorContext) {
315-
if (isset($silencedLogs[$h = spl_object_hash($exception)])) {
315+
if (isset($silencedLogs[$id = spl_object_id($exception)])) {
316316
continue;
317317
}
318-
$silencedLogs[$h] = true;
318+
$silencedLogs[$id] = true;
319319
$count['scream_count'] += $exception->count;
320320
} else {
321321
++$count['deprecation_count'];

src/Symfony/Component/Lock/Tests/LockTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -476,18 +476,18 @@ public function testAcquireReadTwiceWithExpiration()
476476
public function save(Key $key): void
477477
{
478478
$key->reduceLifetime($this->initialTtl);
479-
$this->keys[spl_object_hash($key)] = $key;
479+
$this->keys[spl_object_id($key)] = $key;
480480
$this->checkNotExpired($key);
481481
}
482482

483483
public function delete(Key $key): void
484484
{
485-
unset($this->keys[spl_object_hash($key)]);
485+
unset($this->keys[spl_object_id($key)]);
486486
}
487487

488488
public function exists(Key $key): bool
489489
{
490-
return isset($this->keys[spl_object_hash($key)]);
490+
return isset($this->keys[spl_object_id($key)]);
491491
}
492492

493493
public function putOffExpiration(Key $key, $ttl): void
@@ -520,18 +520,18 @@ public function testAcquireTwiceWithExpiration()
520520
public function save(Key $key): void
521521
{
522522
$key->reduceLifetime($this->initialTtl);
523-
$this->keys[spl_object_hash($key)] = $key;
523+
$this->keys[spl_object_id($key)] = $key;
524524
$this->checkNotExpired($key);
525525
}
526526

527527
public function delete(Key $key): void
528528
{
529-
unset($this->keys[spl_object_hash($key)]);
529+
unset($this->keys[spl_object_id($key)]);
530530
}
531531

532532
public function exists(Key $key): bool
533533
{
534-
return isset($this->keys[spl_object_hash($key)]);
534+
return isset($this->keys[spl_object_id($key)]);
535535
}
536536

537537
public function putOffExpiration(Key $key, $ttl): void

src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,19 +164,19 @@ public function __construct(
164164
*/
165165
protected function isCircularReference(object $object, array &$context): bool
166166
{
167-
$objectHash = spl_object_hash($object);
167+
$objectId = spl_object_id($object);
168168

169169
$circularReferenceLimit = $context[self::CIRCULAR_REFERENCE_LIMIT] ?? $this->defaultContext[self::CIRCULAR_REFERENCE_LIMIT];
170-
if (isset($context[self::CIRCULAR_REFERENCE_LIMIT_COUNTERS][$objectHash])) {
171-
if ($context[self::CIRCULAR_REFERENCE_LIMIT_COUNTERS][$objectHash] >= $circularReferenceLimit) {
172-
unset($context[self::CIRCULAR_REFERENCE_LIMIT_COUNTERS][$objectHash]);
170+
if (isset($context[self::CIRCULAR_REFERENCE_LIMIT_COUNTERS][$objectId])) {
171+
if ($context[self::CIRCULAR_REFERENCE_LIMIT_COUNTERS][$objectId] >= $circularReferenceLimit) {
172+
unset($context[self::CIRCULAR_REFERENCE_LIMIT_COUNTERS][$objectId]);
173173

174174
return true;
175175
}
176176

177-
++$context[self::CIRCULAR_REFERENCE_LIMIT_COUNTERS][$objectHash];
177+
++$context[self::CIRCULAR_REFERENCE_LIMIT_COUNTERS][$objectId];
178178
} else {
179-
$context[self::CIRCULAR_REFERENCE_LIMIT_COUNTERS][$objectHash] = 1;
179+
$context[self::CIRCULAR_REFERENCE_LIMIT_COUNTERS][$objectId] = 1;
180180
}
181181

182182
return false;

src/Symfony/Component/Validator/Tests/Fixtures/FakeMetadataFactory.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ class FakeMetadataFactory implements MetadataFactoryInterface
2121

2222
public function getMetadataFor($class): MetadataInterface
2323
{
24-
$hash = null;
24+
$objectId = null;
2525

2626
if (\is_object($class)) {
27-
$hash = spl_object_hash($class);
27+
$objectId = spl_object_id($class);
2828
$class = $class::class;
2929
}
3030

@@ -33,8 +33,8 @@ public function getMetadataFor($class): MetadataInterface
3333
}
3434

3535
if (!isset($this->metadatas[$class])) {
36-
if (isset($this->metadatas[$hash])) {
37-
return $this->metadatas[$hash];
36+
if (isset($this->metadatas[$objectId])) {
37+
return $this->metadatas[$objectId];
3838
}
3939

4040
throw new NoSuchMetadataException(sprintf('No metadata for "%s"', $class));
@@ -45,18 +45,18 @@ public function getMetadataFor($class): MetadataInterface
4545

4646
public function hasMetadataFor($class): bool
4747
{
48-
$hash = null;
48+
$objectId = null;
4949

5050
if (\is_object($class)) {
51-
$hash = spl_object_hash($class);
51+
$objectId = spl_object_id($class);
5252
$class = $class::class;
5353
}
5454

5555
if (!\is_string($class)) {
5656
return false;
5757
}
5858

59-
return isset($this->metadatas[$class]) || isset($this->metadatas[$hash]);
59+
return isset($this->metadatas[$class]) || isset($this->metadatas[$objectId]);
6060
}
6161

6262
public function addMetadata($metadata)
@@ -66,7 +66,7 @@ public function addMetadata($metadata)
6666

6767
public function addMetadataForValue($value, MetadataInterface $metadata)
6868
{
69-
$key = \is_object($value) ? spl_object_hash($value) : $value;
69+
$key = \is_object($value) ? spl_object_id($value) : $value;
7070
$this->metadatas[$key] = $metadata;
7171
}
7272
}

0 commit comments

Comments
 (0)
0