Skip to content

Commit 6bf109e

Browse files
committed
Improve util.UUID constructor performance when passed util.Bytes
1 parent ba08bf9 commit 6bf109e

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

ChangeLog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@ XP Framework Core ChangeLog
33

44
## ?.?.? / ????-??-??
55

6+
## 12.3.0 / 2025-02-09
7+
68
### Bugfixes
79

810
* Fixed issue #348: Class "rt.script.php" could not be found - @thekid
911

1012
### Features
1113

14+
* Improved `util.UUID` constructor performance when passed `util.Bytes`
15+
(@thekid)
1216
* Changed `util.Bytes` constructor to accept zero or more chunks, each of
1317
which may be `string[]`, `int[]`, `string` or `util.Bytes`, from which
1418
the underlying byte buffer will be concatenated. Improved performance

src/main/php/util/UUID.class.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@
5050
* ```
5151
*
5252
* @see https://datatracker.ietf.org/doc/rfc4122/
53-
* @test net.xp_framework.unittest.util.UUIDTest
53+
* @test util.unittest.UUIDTest
5454
*/
5555
class UUID implements Value {
56-
const FORMAT = '%04x%04x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x';
56+
const FORMAT= '%04x%04x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x';
5757

5858
public static $NS_DNS, $NS_URL, $NS_OID, $NS_X500;
5959

@@ -83,7 +83,14 @@ static function __static() {
8383
*/
8484
public function __construct($arg) {
8585
if ($arg instanceof Bytes) {
86-
$this->populate(implode('-', unpack('H8a/H4b/H4c/H4d/H12e', $arg)));
86+
$r= unpack('Ntime_low/ntime_mid/ntime_hi_and_version/Cclock_seq_hi_and_reserved/Cclock_seq_low/C6node', $arg);
87+
$this->version= ($r['time_hi_and_version'] >> 12) & 0xF;
88+
$this->time_low= $r['time_low'];
89+
$this->time_mid= $r['time_mid'];
90+
$this->time_hi_and_version= $r['time_hi_and_version'];
91+
$this->clock_seq_low= $r['clock_seq_low'];
92+
$this->clock_seq_hi_and_reserved= $r['clock_seq_hi_and_reserved'];
93+
$this->node= [$r['node1'], $r['node2'], $r['node3'], $r['node4'], $r['node5'], $r['node6']];
8794
} else if (is_array($arg)) {
8895
$this->version= $arg[0];
8996
$this->time_low= $arg[1];

0 commit comments

Comments
 (0)