Skip to content

Commit 007fb7f

Browse files
authored
Optimize equals() and cmp() (#29)
1 parent d5ce881 commit 007fb7f

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

src/UUID.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ private static function stripExtras(string $uuid): string
9898
throw new \InvalidArgumentException('Invalid UUID string: ' . $uuid);
9999
}
100100
// Get hexadecimal components of UUID
101-
return str_replace(self::REPLACE_ARR, '', $uuid);
101+
return strtolower(str_replace(self::REPLACE_ARR, '', $uuid));
102102
}
103103

104104
/** @internal */
@@ -239,7 +239,7 @@ public static function isValid(string $uuid): bool
239239
*/
240240
public static function equals(string $uuid1, string $uuid2): bool
241241
{
242-
return self::getBytes($uuid1) === self::getBytes($uuid2);
242+
return self::stripExtras($uuid1) === self::stripExtras($uuid2);
243243
}
244244

245245
/**
@@ -285,7 +285,7 @@ public static function getVersion(string $uuid): int
285285
*/
286286
public static function cmp(string $uuid1, string $uuid2): int
287287
{
288-
return strcmp(self::getBytes($uuid1), self::getBytes($uuid2));
288+
return strcmp(self::stripExtras($uuid1), self::stripExtras($uuid2));
289289
}
290290

291291
/**
@@ -296,7 +296,7 @@ public static function cmp(string $uuid1, string $uuid2): int
296296
*/
297297
public static function toString(string $uuid): string
298298
{
299-
$uhex = strtolower(self::stripExtras($uuid));
299+
$uhex = self::stripExtras($uuid);
300300
return sprintf(
301301
'%08s-%04s-%04s-%04s-%12s',
302302
substr($uhex, 0, 8),

0 commit comments

Comments
 (0)