/** *Addaparticularlookaheadandstate. * *@paramlookahead *@paramstate *@returneithersameoranewLAStatecontainingthegivenlookaheadandstate.
*/ publicfinal LAState add(int lookahead, Object state) {
LAState ret; if (gapLength > 0) { // enough space
moveGap(size());
ret = this;
} else { // no more space // Called when doing TokenSequence.moveNext() - tokens get created lazily // Double the capacity - Token lists should call trimToSize() after finishing
ret = upgrade((capacity() + 1) << 1, getClass());
reallocate(ret, size());
}
Class laStateCls; if ((laStateCls = ret.addToGapStart(lookahead, state)) != null) {
ret = upgrade(capacity() + 1, laStateCls);
reallocate(ret, size());
ret.addToGapStart(lookahead, state);
}
publicfinal LAState addAll(int index, LAState laState) {
LAState ret; int laStateSize = laState.size(); if (!isUpgrade(laState.getClass()) && gapLength > laStateSize) { // enough space
moveGap(index);
ret = this;
} else { // no more space // Called when fixing token list by TokenListUpdater // Leave 10% for growth
ret = upgrade((int)((capacity() + laStateSize) * 110L / 100), laState.getClass());
reallocate(ret, index);
}
protectedvoid copyData(int srcRawIndex, LAState tgt, int dstRawIndex, int len) { if (tgt.getClass() == getClass()) { // same type
System.arraycopy(laBytes, srcRawIndex, ((NoState)tgt).laBytes, dstRawIndex, len);
} elseif (tgt.getClass() == ByteState.class) { short[] laStateShorts = ((ByteState)tgt).laStateShorts; while (--len >= 0) {
laStateShorts[dstRawIndex++] = (short)(laBytes[srcRawIndex++] | 0xFF00);
}
} else { // large state int[] las = ((LargeState)tgt).lookaheads; // No need to operate on tgt.states as they will remain nulls while (--len >= 0) {
las[dstRawIndex++] = laBytes[srcRawIndex++];
}
}
}
protectedvoid moveData(int srcRawIndex, int dstRawIndex, int len) {
System.arraycopy(laBytes, srcRawIndex, laBytes, dstRawIndex, len);
}
protectedvoid copyData(int srcRawIndex, LAState tgt, int dstRawIndex, int len) { if (tgt.getClass() == getClass()) { // same type
System.arraycopy(laStateShorts, srcRawIndex, ((ByteState)tgt).laStateShorts, dstRawIndex, len);
} else { // large state int[] las = ((LargeState)tgt).lookaheads;
Object[] states = ((LargeState)tgt).states; while (--len >= 0) { int val = laStateShorts[srcRawIndex++] & 0xFFFF;
las[dstRawIndex] = val & 0xFF;
val &= 0xFF00; if (val != 0xFF00) { // not null state
states[dstRawIndex] = IntegerCache.integer(val >> 8);
}
dstRawIndex++;
}
}
}
protectedvoid moveData(int srcRawIndex, int dstRawIndex, int len) {
System.arraycopy(laStateShorts, srcRawIndex, laStateShorts, dstRawIndex, len);
}
@Override protectedvoid removeUpdate(int index, int count) { while (--count >= 0) {
states[index + count] = null; // clear the state to allow its gc
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.