mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 23:04:50 +02:00
8310502: Optimization for j.l.Long.fastUUID()
Reviewed-by: liach, alanb
This commit is contained in:
parent
07734f6dde
commit
20f7d05ef2
5 changed files with 96 additions and 43 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -25,10 +25,13 @@
|
|||
|
||||
package java.util;
|
||||
|
||||
import java.nio.charset.CharacterCodingException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.*;
|
||||
|
||||
import jdk.internal.access.JavaLangAccess;
|
||||
import jdk.internal.access.SharedSecrets;
|
||||
import jdk.internal.util.ByteArray;
|
||||
|
||||
/**
|
||||
* A class that represents an immutable universally unique identifier (UUID).
|
||||
|
@ -463,7 +466,43 @@ public final class UUID implements java.io.Serializable, Comparable<UUID> {
|
|||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return jla.fastUUID(leastSigBits, mostSigBits);
|
||||
long lsb = leastSigBits;
|
||||
long msb = mostSigBits;
|
||||
byte[] buf = new byte[36];
|
||||
ByteArray.setLong(
|
||||
buf,
|
||||
0,
|
||||
HexDigits.digit((int) (msb >> 56), (int) (msb >> 48), (int) (msb >> 40), (int) (msb >> 32)));
|
||||
buf[8] = '-';
|
||||
ByteArray.setInt(
|
||||
buf,
|
||||
9,
|
||||
HexDigits.digit(((int) msb) >> 24, ((int) msb) >> 16));
|
||||
buf[13] = '-';
|
||||
ByteArray.setInt(
|
||||
buf,
|
||||
14,
|
||||
HexDigits.digit(((int) msb) >> 8, (int) msb));
|
||||
buf[18] = '-';
|
||||
ByteArray.setInt(
|
||||
buf,
|
||||
19,
|
||||
HexDigits.digit((int) (lsb >> 56), (int) (lsb >> 48)));
|
||||
buf[23] = '-';
|
||||
ByteArray.setLong(
|
||||
buf,
|
||||
24,
|
||||
HexDigits.digit(((int) (lsb >> 40)), (int) (lsb >> 32), ((int) lsb) >> 24, ((int) lsb) >> 16));
|
||||
ByteArray.setInt(
|
||||
buf,
|
||||
32,
|
||||
HexDigits.digit(((int) lsb) >> 8, (int) lsb));
|
||||
|
||||
try {
|
||||
return jla.newStringNoRepl(buf, StandardCharsets.ISO_8859_1);
|
||||
} catch (CharacterCodingException cce) {
|
||||
throw new AssertionError(cce);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue