提交 df786086 authored 作者: Thomas Mueller's avatar Thomas Mueller

Faster UUID parsing.

上级 16a8bd79
...@@ -90,20 +90,23 @@ public class ValueUuid extends Value { ...@@ -90,20 +90,23 @@ public class ValueUuid extends Value {
* @return the UUID * @return the UUID
*/ */
public static ValueUuid get(String s) { public static ValueUuid get(String s) {
long high = 0, low = 0; long low = 0, high = 0;
int i = 0; for (int i = 0, j = 0; i < s.length(); i++) {
for (int j = 0; i < s.length() && j < 16; i++) { char c = s.charAt(i);
char ch = s.charAt(i); if (c >= '0' && c <= '9') {
if (ch != '-') { low = (low << 4) | (c - '0');
high = (high << 4) | Character.digit(ch, 16); } else if (c >= 'a' && c <= 'f') {
j++; low = (low << 4) | (c - 'a' + 0xa);
} else if (c == '-') {
continue;
} else if (c >= 'A' && c <= 'F') {
low = (low << 4) | (c - 'A' + 0xa);
} else {
continue;
} }
} if (j++ == 15) {
for (int j = 0; i < s.length() && j < 16; i++) { high = low;
char ch = s.charAt(i); low = 0;
if (ch != '-') {
low = (low << 4) | Character.digit(ch, 16);
j++;
} }
} }
return (ValueUuid) Value.cache(new ValueUuid(high, low)); return (ValueUuid) Value.cache(new ValueUuid(high, low));
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论