Permalink
Browse files

some small performance improvements

  • Loading branch information...
1 parent 76d382f commit 4b2dfce14f16d95376724a248aca029789df3b05 Jonathan Leibiusky committed Apr 21, 2011
Showing with 52 additions and 11 deletions.
  1. +52 −11 src/main/java/com/github/xetorthio/Fastu.java
@@ -12,29 +12,70 @@ public static String decode(byte[] data) {
len++;
offset++;
} else {
- int size = 0;
int uc = 0;
if ((data[offset] & 0xE0) == 0xC0) {
- size = 1;
uc = (int) (data[offset] & 0x1F);
+ offset++;
+ uc <<= 6;
+ uc |= (int) (data[offset] & 0x3F);
+ offset++;
} else if ((data[offset] & 0xF0) == 0xE0) {
- size = 2;
uc = (int) (data[offset] & 0x0F);
+ offset++;
+ uc <<= 6;
+ uc |= (int) (data[offset] & 0x3F);
+ offset++;
+ uc <<= 6;
+ uc |= (int) (data[offset] & 0x3F);
+ offset++;
+
} else if ((data[offset] & 0xF8) == 0xF0) {
- size = 3;
uc = (int) (data[offset] & 0x07);
+ offset++;
+ uc <<= 6;
+ uc |= (int) (data[offset] & 0x3F);
+ offset++;
+ uc <<= 6;
+ uc |= (int) (data[offset] & 0x3F);
+ offset++;
+ uc <<= 6;
+ uc |= (int) (data[offset] & 0x3F);
+ offset++;
+
} else if ((data[offset] & 0xFC) == 0xF8) {
- size = 4;
uc = (int) (data[offset] & 0x03);
+ offset++;
+ uc <<= 6;
+ uc |= (int) (data[offset] & 0x3F);
+ offset++;
+ uc <<= 6;
+ uc |= (int) (data[offset] & 0x3F);
+ offset++;
+ uc <<= 6;
+ uc |= (int) (data[offset] & 0x3F);
+ offset++;
+ uc <<= 6;
+ uc |= (int) (data[offset] & 0x3F);
+ offset++;
+
} else if ((data[offset] & 0xFE) == 0xFC) {
- size = 5;
uc = (int) (data[offset] & 0x01);
- }
- ++offset;
- int limit = offset + size;
- for (; offset < limit; offset++) {
+ offset++;
+ uc <<= 6;
+ uc |= (int) (data[offset] & 0x3F);
+ offset++;
+ uc <<= 6;
+ uc |= (int) (data[offset] & 0x3F);
+ offset++;
+ uc <<= 6;
+ uc |= (int) (data[offset] & 0x3F);
+ offset++;
+ uc <<= 6;
+ uc |= (int) (data[offset] & 0x3F);
+ offset++;
uc <<= 6;
uc |= (int) (data[offset] & 0x3F);
+ offset++;
}
len = toChars(uc, chars, len);
@@ -56,4 +97,4 @@ public static int toChars(int codePoint, char[] dst, int index) {
dst[index] = (char) ((offset >>> 10) + Character.MIN_HIGH_SURROGATE);
return index + 2;
}
-}
+}

0 comments on commit 4b2dfce

Please sign in to comment.