public void testCopyHeapCharBuffer() { String s = "abcde"; CharBuffer buffer = CharBuffer.allocate(s.length()); buffer.append(s); buffer.rewind(); assertNotNull(CharArrayUtil.fromSequenceWithoutCopying(buffer)); assertNotNull(CharArrayUtil.fromSequenceWithoutCopying(buffer.subSequence(0, 5))); // assertNull(CharArrayUtil.fromSequenceWithoutCopying(buffer.subSequence(0, 4))); // end index // is not checked assertNull(CharArrayUtil.fromSequenceWithoutCopying(buffer.subSequence(1, 5))); assertNull(CharArrayUtil.fromSequenceWithoutCopying(buffer.subSequence(1, 2))); }
private static ImmutableText valueOf(@NotNull CharSequence str, int start, int end) { int length = end - start; if (length <= BLOCK_SIZE) { return new ImmutableText(CharArrayUtil.fromSequence(str, start, end)); } // Splits on a block boundary. int half = ((length + BLOCK_SIZE) >> 1) & BLOCK_MASK; return new ImmutableText(valueOf(str, start, start + half), valueOf(str, start + half, end)); }