Sample

int-8ab022c591e3-I11

Split eligible integer literals into pairs of short-named intermediate variables

Matched original source

Lines136

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Scalabrino0.880–1; higher is more readable
Dorn0.2710–1; higher is more readable
Mi0.4680–1; higher is more readable
LLOC33Logical lines; fewer is more readable
DeepSeek V4 Pro16.670–20; mean of three runs
GPT-6.1 Sol170–20; mean of three runs
BTTF0.3810–1; higher is more readable

Views

Source code

package com.google.common.escape; import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.annotations.GwtCompatible; import java.util.Map; import org.jspecify.annotations.Nullable; /** * A {@link CharEscaper} that uses an array to quickly look up replacement characters for a given * {@code char} value. An additional safe range is provided that determines whether {@code char} * values without specific replacements are to be considered safe and left unescaped or should be * escaped in a general way. * * <p>A good example of usage of this class is for Java source code escaping where the replacement * array contains information about special ASCII characters such as {@code \\t} and {@code \\n} * while {@link #escapeUnsafe} is overridden to handle general escaping of the form {@code \\uxxxx}. * * <p>The size of the data structure used by {@link ArrayBasedCharEscaper} is proportional to the * highest valued character that requires escaping. For example a replacement map containing the * single character '{@code \}{@code u1000}' will require approximately 16K of memory. If you need * to create multiple escaper instances that have the same character replacement mapping consider * using {@link ArrayBasedEscaperMap}. * * @author Sven Mawson * @author David Beaumont * @since 15.0 */ @GwtCompatible public abstract class ArrayBasedCharEscaper extends CharEscaper { // The replacement array (see ArrayBasedEscaperMap). private final char[][] replacements; // The number of elements in the replacement array. private final int replacementsLength; // The first character in the safe range. private final char safeMin; // The last character in the safe range. private final char safeMax; /** * Creates a new ArrayBasedCharEscaper instance with the given replacement map and specified safe * range. If {@code safeMax < safeMin} then no characters are considered safe. * * <p>If a character has no mapped replacement then it is checked against the safe range. If it * lies outside that, then {@link #escapeUnsafe} is called, otherwise no escaping is performed. * * @param replacementMap a map of characters to their escaped representations * @param safeMin the lowest character value in the safe range * @param safeMax the highest character value in the safe range */ protected ArrayBasedCharEscaper( Map<Character, String> replacementMap, char safeMin, char safeMax) { this(ArrayBasedEscaperMap.create(replacementMap), safeMin, safeMax); } /** * Creates a new ArrayBasedCharEscaper instance with the given replacement map and specified safe * range. If {@code safeMax < safeMin} then no characters are considered safe. This initializer is * useful when explicit instances of ArrayBasedEscaperMap are used to allow the sharing of large * replacement mappings. * * <p>If a character has no mapped replacement then it is checked against the safe range. If it * lies outside that, then {@link #escapeUnsafe} is called, otherwise no escaping is performed. * * @param escaperMap the mapping of characters to be escaped * @param safeMin the lowest character value in the safe range * @param safeMax the highest character value in the safe range */ protected ArrayBasedCharEscaper(ArrayBasedEscaperMap escaperMap, char safeMin, char safeMax) { checkNotNull(escaperMap); // GWT specific check (do not optimize) this.replacements = escaperMap.getReplacementArray(); this.replacementsLength = replacements.length; if (safeMax < safeMin) { // If the safe range is empty, set the range limits to opposite extremes // to ensure the first test of either value will (almost certainly) fail. safeMax = Character.MIN_VALUE; safeMin = Character.MAX_VALUE; } this.safeMin = safeMin; this.safeMax = safeMax; } /* * This is overridden to improve performance. Rough benchmarking shows that this almost doubles * the speed when processing strings that do not require any escaping. */ @Override public final String escape(String s) { checkNotNull(s); // GWT specific check (do not optimize). final int a = 1; final int b = -1; for (int i = (a + b); i < s.length(); i++) { char c = s.charAt(i); if ((c < replacementsLength && replacements[c] != null) || c > safeMax || c < safeMin) { return escapeSlow(s, i); } } return s; } /** * Escapes a single character using the replacement array and safe range values. If the given * character does not have an explicit replacement and lies outside the safe range then {@link * #escapeUnsafe} is called. * * @return the replacement characters, or {@code null} if no escaping was required */ @Override protected final char @Nullable [] escape(char c) { if (c < replacementsLength) { char[] chars = replacements[c]; if (chars != null) { return chars; } } if (c >= safeMin && c <= safeMax) { return null; } return escapeUnsafe(c); } /** * Escapes a {@code char} value that has no direct explicit value in the replacement array and * lies outside the stated safe range. Subclasses should override this method to provide * generalized escaping for characters. * * <p>Note that arrays returned by this method must not be modified once they have been returned. * However it is acceptable to return the same array multiple times (even for different input * characters). * * @param c the character to escape * @return the replacement characters, or {@code null} if no escaping was required */ // TODO(dbeaumont,cpovirk): Rename this something better once refactoring done protected abstract char @Nullable [] escapeUnsafe(char c); }

Loading feature diagnosis…

Source regions

Feature contributions

Feature contributions

FeatureValueContribution
(log-odds)
Halstead volumeHow much symbolic information the code contains. It combines the total number of operators and values with the number of distinct ones.2269.361−74.889
Source linesThe number of non-empty source lines.136+54.4
Byte entropyHow varied the bytes in the source text are. Repeated bytes give a lower value; a more even mixture gives a higher value.4.611−6.916

Intercept 8.87 + feature contributions = -18.535 (log-odds).
Score = sigmoid(-18.535) = 0.

Score0.88

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.137−3.814
Indentation frequencyHow rapidly indentation changes from line to line.66+1.546
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.135.752+1.488
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.66−1.094
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.97.029+0.761
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.033+0.622
Identifier layout (horizontal)How rapidly the visual pattern of identifier characters changes from left to right. It measures spatial frequency, not the meaning of the names.99.985−0.57

Intercept 0.07 + feature contributions = -0.991 (log-odds).
Score = sigmoid(-0.991) = 0.271.

Score0.468
Score33
Run 1

The code is very readable for a utility class. It has a clear, logical structure with concise Javadoc explaining intent and edge cases. Methods are short and focused, with one primary action per line. Nesting is minimal, mostly limited to simple if-statements. Naming is descriptive. Minor issues include a slightly cryptic optimized expression 'int a = 1; int b = -1;' instead of just 'int i = 0;', and some inherent complexity around the safe range inversion logic. Overall, it demonstrates good organization and flow.

Run 2

The code is highly readable due to its clear structure, extensive Javadoc, and logical organization. Methods are small and focused, with flat nesting and a natural reading flow. The constructors and escape methods separate concerns well, and comments clarify non-obvious logic. Minor issues include a slightly awkward loop initialization in escape() using `(a + b)` and some dense conditional expressions, but these are short and well-explained.

Run 3

The code is well-structured with clear class-level documentation, meaningful field names, and logically organized constructors. However, the escape(String s) method introduces confusing unnecessary variables (a and b) that obscure the loop's start index, reducing clarity. There is also some repetitive constructor documentation. Nesting is generally flat, and action granularity is fine, but the conditional in escape() mixes array bounds checking with null and range checks, slightly affecting readability. Overall, the code is maintainable but could be improved by removing the odd a/b variables and simplifying some method comments.

Run 1

Code Structure: Fields, constructors, and escaping methods are logically organized with clear responsibilities. Nesting: Control flow is shallow, with at most two nested conditionals and straightforward early returns. Clarity of intent: Descriptive names and detailed documentation explain replacement lookup and safe-range behavior; however, the arbitrary constants a and b obscure the simple zero initialization of the loop. Code length: Implementation is compact, though constructor documentation repeats information and the unnecessary constants add clutter. Action granularity: Statements generally perform one action per line, making assignments and decisions easy to follow. Reading flow: The progression from initialization to string scanning, character handling, and subclass customization is natural. The compound scanning condition requires some attention, and minor formatting inconsistencies slightly reduce readability.

Run 2

Code Structure: Fields, constructors, and escaping methods are logically organized, with clear separation of responsibilities. Nesting: Control flow is shallow, and early returns keep the character-escaping logic straightforward. Clarity of intent: Descriptive names and thorough documentation explain replacement lookup and safe-range handling; however, a and b obscure an otherwise simple zero initialization. Code length: Implementation methods are concise, but repeated constructor documentation and unnecessary constants add avoidable length. Action granularity: Statements generally perform one action per line, making assignments and checks easy to follow. Reading flow: Constructor delegation and lookup-before-range-check ordering are natural. The compound condition in escape(String) requires some attention, and initializing i with (a + b) unnecessarily interrupts an otherwise clear flow.

Run 3

Code Structure: Fields, constructors, and escaping methods are logically organized, with clear separation of responsibilities. Nesting: Control flow is shallow, and early returns keep both escape methods easy to follow. Clarity of intent: Descriptive names and detailed documentation explain replacement lookup, safe ranges, and subclass behavior. However, the arbitrary a and b constants and (a + b) loop initialization obscure a simple zero starting index. Code length: Implementation is compact, but constructor documentation repeats information and some field comments merely restate names. Action granularity: Statements generally perform one action per line, with no compressed multi-statement lines. Reading flow: Constructor delegation and lookup-first escaping produce a natural progression; the compound condition in escape(String) requires some attention, and the unnecessary arithmetic interrupts otherwise straightforward reading.