Skip to content

Commit 389e788

Browse files
authored
Minor toString() speed optimization (#35)
1 parent 06e5f18 commit 389e788

1 file changed

Lines changed: 4 additions & 10 deletions

File tree

src/UUID.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
/**
88
* Represents a universally unique identifier (UUID), according to RFC 4122.
99
*
10-
* This class provides the static methods `uuid3()`, `uuid4()`, `uuid5()`, and
11-
* `uuid6()` for generating version 3, 4, 5, and 6 (draft) UUIDs.
10+
* This class provides the static methods `uuid3()`, `uuid4()`, `uuid5()`,
11+
* `uuid6()`, and `uuid7()` for generating version 3, 4, 5, 6 (draft), and
12+
* 7 (draft) UUIDs.
1213
*
1314
* If all you want is a unique ID, you should call `uuid4()`.
1415
*
@@ -301,14 +302,7 @@ public static function cmp(string $uuid1, string $uuid2): int
301302
public static function toString(string $uuid): string
302303
{
303304
$uhex = self::stripExtras($uuid);
304-
return sprintf(
305-
'%08s-%04s-%04s-%04s-%12s',
306-
substr($uhex, 0, 8),
307-
substr($uhex, 8, 4),
308-
substr($uhex, 12, 4),
309-
substr($uhex, 16, 4),
310-
substr($uhex, 20, 12)
311-
);
305+
return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split($uhex, 4));
312306
}
313307

314308
/**

0 commit comments

Comments
 (0)