Code with Finding: |
class SourceMap2.LineMapEncoder {
/**
* The source map line map is consists of a series of entries each
* representing a map entry and a repetition count of that entry.
*
* @param out The entry destination.
* @param id The id for the entry.
* @param lastId The previous id written, used to generate a relative
* map id.
* @param reps The number of times the id is repeated in the map.
* @throws IOException
*/
static void encodeEntry(Appendable out, int id, int lastId, int reps)
throws IOException {
Preconditions.checkState(reps > 0);
int relativeIdLength = getRelativeMappingIdLength(id, lastId);
int relativeId = getRelativeMappingId(id, relativeIdLength, lastId);
String relativeIdString = valueToBase64(relativeId, relativeIdLength);
// If we can, we use a single base64 digit to encode both the id length
// and the repetition count. The current best division of the base64
// digit (which has 6 bits) is 2 bits for the id length (1-4 digits) and
// 4 bit for the repetition count (1-16 repetitions). If either of these
// two values are exceeded a "!" is written (a non-base64 character) to
// signal the a full base64 character is used for repetition count and
// the mapping id length. As the repetition count can exceed 64, we
// allow the "escape" ("!") to be repeated to signal additional
// repetition count length characters. It is extremely unlikely that
// mapping id length will exceed 64 base64 characters in length so
// additional "!" don't signal additional id length characters.
if (reps > 16 || relativeIdLength > 4) {
String repsString = valueToBase64(reps -1, 1);
for (int i = 0; i < repsString.length(); i++) {
// TODO(johnlenz): update this to whatever is agreed to.
out.append('!');
}
String sizeId = valueToBase64(relativeIdString.length() -1, 1);
out.append(sizeId);
out.append(repsString);
} else {
int prefix = ((reps -1) << 2) + (relativeIdString.length() -1);
Preconditions.checkState(prefix < 64 && prefix >= 0,
"prefix (%s) reps(%s) map id size(%s)",
prefix, reps, relativeIdString.length());
out.append(valueToBase64(prefix, 1));
}
out.append(relativeIdString);
}
}
|