offset1 = 0;
} else {
seg1 = -seg1 - 2;
offset1 = end - startOffsets[seg1];
}
FastStringBuffer startSegment = (FastStringBuffer)segments.get(seg0);
// We've had reports (28 Feb 2007) of an NPE here, which we couldn't reproduce.
// The following code is designed to produce diagnostics if it ever happens again
if (startSegment == null) {
dumpDataStructure();
throw new NullPointerException("startSegment: subSequence(" + start + ", " + end + ")");
}
if (seg0 == seg1) {
// the required substring is all in one segment
return startSegment.subSequence(offset0, offset1);
} else {
// copy the data into a new FastStringBuffer. This case should be exceptional
FastStringBuffer sb = new FastStringBuffer(end - start);
sb.append(startSegment.subSequence(offset0, startSegment.length()));
for (int i=seg0+1; i<seg1; i++) {
sb.append(((FastStringBuffer)segments.get(i)));
}
if (offset1 > 0) {
sb.append(((FastStringBuffer)segments.get(seg1)).subSequence(0, offset1));
}
return sb;
}
}