Source:
<code>private int filterWithDictionary(Page page, int[] positions, int positionCount, RuntimeException[] errors) { int outputCount = 0; DictionaryBlock block = (DictionaryBlock) page.getBlock(0); Block dictionary = block.getDictionary(); if (dictionary != previousDictionary) { previousDictionary = dictionary; int numEntries = dictionary.getPositionCount(); dictionaryPage = new Page(numEntries, dictionary); <START> if (dictionaryResults == null || dictionaryResults.length < numEntries) { <END> dictionaryResults = new byte[numEntries]; } else { fill(dictionaryResults, 0, numEntries, FILTER_NOT_EVALUATED); } } for (int i = 0; i < positionCount; i++) { int position = positions[i]; int dictionaryPosition = block.getId(position); byte result = dictionaryResults[dictionaryPosition]; if (result == FILTER_FAILED) { continue; } if (result == FILTER_PASSED) { positions[outputCount++] = position; continue; } try { if (predicate.evaluate(session, page, position)) { positions[outputCount++] = position; dictionaryResults[dictionaryPosition] = FILTER_PASSED; } else { dictionaryResults[dictionaryPosition] = FILTER_FAILED; } } catch (RuntimeException e) { positions[outputCount] = position; errors[outputCount] = e; outputCount++; } } return outputCount; }</code><technical_language>is preferable Arrays.ensureCapacity method for allocating arrays. dictionaryResults = ensureCapacity(dictionaryResults, dictionary.getPositionCount()); fill(dictionaryResults, FILTER_NOT_EVALUATED); If is important avoid extra fill for newly allocated array, consider adding another ensureCapacity method takes a initialize new array re-set existing one. dictionaryResults = ensureCapacity(dictionaryResults, dictionary.getPositionCount(), FILTER_NOT_EVALUATED); public static byte[] ensureCapacity(byte[] buffer, int capacity, byte initialValue) { if (buffer == null || buffer.length < capacity) { byte[] newBuffer = new byte[capacity]; if (initialValue != 0) { fill(buffer, initialValue); } return newBuffer; } fill(buffer, initialValue); return buffer; }</technical_language>

Target:
private int filterWithDictionary(Page page, int[] positions, int positionCount, RuntimeException[] errors) { int outputCount = 0; DictionaryBlock block = (DictionaryBlock) page.getBlock(0); Block dictionary = block.getDictionary(); if (dictionary != previousDictionary) { previousDictionary = dictionary; int numEntries = dictionary.getPositionCount(); dictionaryPage = new Page(numEntries, dictionary); dictionaryResults = ensureCapacity(dictionaryResults, numEntries); fill(dictionaryResults, 0, numEntries, FILTER_NOT_EVALUATED); } for (int i = 0; i < positionCount; i++) { int position = positions[i]; int dictionaryPosition = block.getId(position); byte result = dictionaryResults[dictionaryPosition]; switch (result) { case FILTER_FAILED: continue; case FILTER_PASSED: positions[outputCount] = position; errors[outputCount] = errors[i]; outputCount++; continue; case FILTER_NOT_EVALUATED: try { if (predicate.evaluate(session, dictionaryPage, dictionaryPosition)) { positions[outputCount] = position; errors[outputCount] = errors[i]; outputCount++; dictionaryResults[dictionaryPosition] = FILTER_PASSED; } else { dictionaryResults[dictionaryPosition] = FILTER_FAILED; } } catch (RuntimeException e) { positions[outputCount] = position; errors[outputCount] = e; outputCount++; } break; default: verify(false, "Unexpected filter result: " + result); } } return outputCount; }