Creates a numeric (inlined) representation of the specified token. @param token token to be inlined @return inlined value, or 0 if inlining is not possible
(final byte[] token)
| 43 | * @return inlined value, or {@code 0} if inlining is not possible |
| 44 | */ |
| 45 | public static long pack(final byte[] token) { |
| 46 | // inline integer value |
| 47 | long value = packInt(token); |
| 48 | if(value != -1) return value; |
| 49 | |
| 50 | // short token |
| 51 | final long tl = token.length; |
| 52 | if(tl <= 4) { |
| 53 | value = INLINE | STRING | tl << 32; |
| 54 | int c = 32; |
| 55 | for(final byte b : token) value |= (b & 0xFFL) << (c -= 8); |
| 56 | return value; |
| 57 | } |
| 58 | // compressed whitespace token |
| 59 | if(tl < 16 && ws(token)) { |
| 60 | value = INLINE | STRING | Compress.COMPRESS | tl << 32; |
| 61 | int c = 32; |
| 62 | // upper bit: 09/0A = 0, 0D/20 = 1 |
| 63 | // lower bit: 0A/20 = 0, 09/0D = 1 |
| 64 | for(final byte b : token) value |= (b < 0x0B ? 0L : 1L) << --c | (long) (b & 1) << --c; |
| 65 | return value; |
| 66 | } |
| 67 | // no inlining possible |
| 68 | return 0; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Converts the specified token into a positive integer value. |