Skip to content

Commit

Permalink
feat!: use new jymfony compiler (written in rust/wasm) for better per…
Browse files Browse the repository at this point in the history
…formance
  • Loading branch information
alekitto committed Nov 5, 2023
1 parent f5b7668 commit d546430
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 26 deletions.
16 changes: 8 additions & 8 deletions src/AbstractUid.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,20 @@ export default class AbstractUid extends implementationOf(UidInterface) {
}

/**
* Returns the identifier as a base-32 case insensitive string.
* Returns the identifier as a base-32 case-insensitive string.
*
* @returns {string}
*/
toBase32() {
let uid = this.toBuffer().toString('hex');
uid = __jymfony.sprintf('%02s%04s%04s%04s%04s%04s%04s',
Number.parseInt(uid.substr(0, 2), 16).toString(32),
Number.parseInt(uid.substr(2, 5), 16).toString(32),
Number.parseInt(uid.substr(7, 5), 16).toString(32),
Number.parseInt(uid.substr(12, 5), 16).toString(32),
Number.parseInt(uid.substr(17, 5), 16).toString(32),
Number.parseInt(uid.substr(22, 5), 16).toString(32),
Number.parseInt(uid.substr(27, 5), 16).toString(32),
Number.parseInt(uid.substring(0, 2), 16).toString(32),
Number.parseInt(uid.substring(2, 7), 16).toString(32),
Number.parseInt(uid.substring(7, 12), 16).toString(32),
Number.parseInt(uid.substring(12, 17), 16).toString(32),
Number.parseInt(uid.substring(17, 22), 16).toString(32),
Number.parseInt(uid.substring(22, 27), 16).toString(32),
Number.parseInt(uid.substring(27, 32), 16).toString(32),
);

return __jymfony.strtr(uid, {
Expand Down
24 changes: 12 additions & 12 deletions src/Uuid.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@ export default class Uuid extends AbstractUid {

uuid = __jymfony.sprintf(
'%s-%s-%s-%s-%s',
uuid.substr(0, 8),
uuid.substr(8, 4),
uuid.substr(12, 4),
uuid.substr(16, 4),
uuid.substr(20),
uuid.substring(0, 8),
uuid.substring(8, 12),
uuid.substring(12, 16),
uuid.substring(16, 20),
uuid.substring(20),
);
} else if (26 === uuid.length && Ulid.isValid(uuid)) {
uuid = (new Ulid(uuid)).toRfc4122();
}

if (__self !== this || 36 !== uuid.length) {
if (__self !== new ReflectionClass(this).getConstructor() || 36 !== uuid.length) {
return new this(uuid);
}

Expand Down Expand Up @@ -100,7 +100,7 @@ export default class Uuid extends AbstractUid {
}

static isValid(uuid) {
if (__self === this) {
if (__self === new ReflectionClass(this).getConstructor()) {
return uuid_is_valid(uuid);
}

Expand Down Expand Up @@ -139,12 +139,12 @@ export default class Uuid extends AbstractUid {

return __jymfony.sprintf(
'%s-%s-%u%s-%s-%s',
uuid.substr(0, 8),
uuid.substr(8, 4),
uuid.substring(0, 8),
uuid.substring(8, 12),
version,
uuid.substr(13, 3),
uuid.substr(16, 4),
uuid.substr(20)
uuid.substring(13, 16),
uuid.substring(16, 20),
uuid.substring(20)
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/UuidV1.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default class UuidV1 extends Uuid {
}

getTime() {
const time = '0' + this._uid.substr(15, 3) + this._uid.substr(9, 4) + this._uid.substr(0, 8);
const time = '0' + this._uid.substring(15, 18) + this._uid.substring(9, 13) + this._uid.substring(0, 8);

return BinaryUtil.timeToFloat(time);
}
Expand Down
2 changes: 1 addition & 1 deletion src/UuidV4.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default class UuidV4 extends Uuid {
uuid.writeUInt8(uuid.readUInt8(8) & 0x3F | 0x80, 8);
uuid = uuid.toString('hex');

this._uid = uuid.substr(0, 8) + '-' + uuid.substr(8, 4) + '-' + uuid.substr(12, 4) + '-' + uuid.substr(16, 4) + '-' + uuid.substr(20, 12);
this._uid = uuid.substring(0, 8) + '-' + uuid.substring(8, 12) + '-' + uuid.substring(12, 16) + '-' + uuid.substring(16, 20) + '-' + uuid.substring(20);
} else {
super.__construct(uuid);
}
Expand Down
8 changes: 4 additions & 4 deletions src/UuidV6.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default class UuidV6 extends Uuid {
__construct(uuid = null) {
if (null === uuid) {
const uuid = uuid_create(UuidV1.TYPE);
this._uid = uuid.substr(15, 3) + uuid.substr(9, 4) + uuid[0] + '-' + uuid.substr(1, 4) + '-6' + uuid.substr(5, 3) + uuid.substr(18, 6);
this._uid = uuid.substring(15, 18) + uuid.substring(9, 13) + uuid[0] + '-' + uuid.substring(1, 5) + '-6' + uuid.substring(5, 8) + uuid.substring(18, 24);

// "uuid_create()" returns a stable "node" that can leak the MAC of the host, but
// UUIDv6 prefers a truly random number here, let's XOR both to preserve the entropy
Expand All @@ -31,7 +31,7 @@ export default class UuidV6 extends Uuid {
seed = [ Math.floor(Math.random() * 0x1000000) - 1, Math.floor(Math.random() * 0x1000000) - 1 ];
}

const buf = Buffer.from('00' + uuid.substr(24, 6) + '00' + uuid.substr(30), 'hex');
const buf = Buffer.from('00' + uuid.substring(24, 30) + '00' + uuid.substring(30), 'hex');
this._uid += __jymfony.sprintf('%06x%06x',
(seed[0] ^ buf.readUInt32BE(0)) | 0x010000,
seed[1] ^ buf.readUInt32BE(4)
Expand All @@ -42,13 +42,13 @@ export default class UuidV6 extends Uuid {
}

getTime() {
const time = '0' + this._uid.substr(0, 8) + this._uid.substr(9, 4) + this._uid.substr(15, 3);
const time = '0' + this._uid.substring(0, 8) + this._uid.substring(9, 13) + this._uid.substring(15, 18);

return BinaryUtil.timeToFloat(time);
}

getNode() {
return this._uid.substr(24);
return this._uid.substring(24);
}
}

Expand Down

0 comments on commit d546430

Please sign in to comment.