private static ByteString balancedConcat(Iterator<ByteString> iterator, int length) { assert length >= 1; ByteString result; if (length == 1) { result = iterator.next(); } else { int halfLength = length >>> 1; ByteString left = balancedConcat(iterator, halfLength); ByteString right = balancedConcat(iterator, length - halfLength); result = left.concat(right); } return result; }
private static ByteString balancedConcat(Iterator<ByteString> iterator, int length) { assert length >= 1; ByteString result; if (length == 1) { result = iterator.next(); } else { int halfLength = length >>> 1; ByteString left = balancedConcat(iterator, halfLength); ByteString right = balancedConcat(iterator, length - halfLength); result = left.concat(right); } return result; }
private static ByteString balancedConcat(Iterator<ByteString> iterator, int length) { assert length >= 1; ByteString result; if (length == 1) { result = iterator.next(); } else { int halfLength = length >>> 1; ByteString left = balancedConcat(iterator, halfLength); ByteString right = balancedConcat(iterator, length - halfLength); result = left.concat(right); } return result; }
/** * Concatenates all byte strings in the iterable and returns the result. * This is designed to run in O(list size), not O(total bytes). * * <p>The returned {@code ByteString} is not necessarily a unique object. * If the list is empty, the returned object is the singleton empty * {@code ByteString}. If the list has only one element, that * {@code ByteString} will be returned without copying. * * @param byteStrings strings to be concatenated * @return new {@code ByteString} */ public static ByteString copyFrom(Iterable<ByteString> byteStrings) { Collection<ByteString> collection; if (!(byteStrings instanceof Collection)) { collection = new ArrayList<ByteString>(); for (ByteString byteString : byteStrings) { collection.add(byteString); } } else { collection = (Collection<ByteString>) byteStrings; } ByteString result; if (collection.isEmpty()) { result = EMPTY; } else { result = balancedConcat(collection.iterator(), collection.size()); } return result; }
/** * Concatenates all byte strings in the iterable and returns the result. * This is designed to run in O(list size), not O(total bytes). * * <p>The returned {@code ByteString} is not necessarily a unique object. * If the list is empty, the returned object is the singleton empty * {@code ByteString}. If the list has only one element, that * {@code ByteString} will be returned without copying. * * @param byteStrings strings to be concatenated * @return new {@code ByteString} */ public static ByteString copyFrom(Iterable<ByteString> byteStrings) { Collection<ByteString> collection; if (!(byteStrings instanceof Collection)) { collection = new ArrayList<ByteString>(); for (ByteString byteString : byteStrings) { collection.add(byteString); } } else { collection = (Collection<ByteString>) byteStrings; } ByteString result; if (collection.isEmpty()) { result = EMPTY; } else { result = balancedConcat(collection.iterator(), collection.size()); } return result; }
/** * Concatenates all byte strings in the iterable and returns the result. * This is designed to run in O(list size), not O(total bytes). * * <p>The returned {@code ByteString} is not necessarily a unique object. * If the list is empty, the returned object is the singleton empty * {@code ByteString}. If the list has only one element, that * {@code ByteString} will be returned without copying. * * @param byteStrings strings to be concatenated * @return new {@code ByteString} */ public static ByteString copyFrom(Iterable<ByteString> byteStrings) { Collection<ByteString> collection; if (!(byteStrings instanceof Collection)) { collection = new ArrayList<ByteString>(); for (ByteString byteString : byteStrings) { collection.add(byteString); } } else { collection = (Collection<ByteString>) byteStrings; } ByteString result; if (collection.isEmpty()) { result = EMPTY; } else { result = balancedConcat(collection.iterator(), collection.size()); } return result; }