8000 minor #36153 [Uid] minor improvements (nicolas-grekas) · symfony/symfony@80672fb · GitHub
[go: up one dir, main page]

Skip to content

Commit 80672fb

Browse files
minor #36153 [Uid] minor improvements (nicolas-grekas)
This PR was merged into the 5.1-dev branch. Discussion ---------- [Uid] minor improvements | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Commits ------- 660326b [Uid] minor improvements
2 parents 7e181b9 + 660326b commit 80672fb

File tree

5 files changed

+25
-3
lines changed

5 files changed

+25
-3
lines changed

phpunit.xml.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
<element key="5"><string>Symfony\Component\Cache\Traits</string></element>
7979
<element key="6"><string>Symfony\Component\Console</string></element>
8080
<element key="7"><string>Symfony\Component\HttpFoundation</string></element>
81+
<element key="8"><string>Symfony\Component\Uid</string></element>
8182
</array>
8283
</element>
8384
</array>

src/Symfony/Component/Uid/AbstractUid.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,13 @@ public function toBase32(): string
7474
*/
7575
public function toRfc4122(): string
7676
{
77-
return uuid_unparse($this->toBinary());
77+
// don't use uuid_unparse(), it's slower
78+
$uuid = bin2hex($this->toBinary());
79+
$uuid = substr_replace($uuid, '-', 8, 0);
80+
$uuid = substr_replace($uuid, '-', 13, 0);
81+
$uuid = substr_replace($uuid, '-', 18, 0);
82+
83+
return substr_replace($uuid, '-', 23, 0);
7884
}
7985

8086
/**

src/Symfony/Component/Uid/Ulid.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*/
2323
class Ulid extends AbstractUid
2424
{
25-
private static $time = -1;
25+
private static $time = '';
2626
private static $rand = [];
2727

2828
public function __construct(string $ulid = null)

src/Symfony/Component/Uid/Uuid.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@ public static function fromString(string $uuid): parent
4141
}
4242

4343
if (16 === \strlen($uuid)) {
44-
$uuid = uuid_unparse($uuid);
44+
// don't use uuid_unparse(), it's slower
45+
$uuid = bin2hex($uuid);
46+
$uuid = substr_replace($uuid, '-', 8, 0);
47+
$uuid = substr_replace($uuid, '-', 13, 0);
48+
$uuid = substr_replace($uuid, '-', 18, 0);
49+
$uuid = substr_replace($uuid, '-', 23, 0);
4550
} elseif (26 === \strlen($uuid) && Ulid::isValid($uuid)) {
4651
$uuid = (new Ulid($uuid))->toRfc4122();
4752
}

src/Symfony/Component/Uid/phpunit.xml.dist

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,14 @@
2727
</exclude>
2828
</whitelist>
2929
</filter>
30+
31+
<listeners>
32+
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener">
33+
<arguments>
34+
<array>
35+
<element key="time-sensitive"><string>Symfony\Component\Uid</string></element>
36+
</array>
37+
</arguments>
38+
</listener>
39+
</listeners>
3040
</phpunit>

0 commit comments

Comments
 (0)
0