MCPcopy Create free account
hub / github.com/antlr/codebuff / precomputedInternal

Method precomputedInternal

output/java_guava/1.4.13/CharMatcher.java:562–586  ·  view source on GitHub ↗

This is the actual implementation of #precomputed, but we bounce calls through a method on Platform so that we can have different behavior in GWT. This implementation tries to be smart in a number of ways. It recognizes cases where the negation is cheaper to precompute than the m

()

Source from the content-addressed store, hash-verified

560 */
561
562 @GwtIncompatible // java.util.BitSet
563 CharMatcher precomputedInternal() {
564 final BitSet table = new BitSet();
565 setBits(table);
566 int totalCharacters = table.cardinality();
567 if (totalCharacters * 2 <= DISTINCT_CHARS) {
568 return precomputedPositive(totalCharacters, table, toString());
569 } else {
570 // TODO(lowasser): is it worth it to worry about the last character of large matchers?
571 table.flip(Character.MIN_VALUE, Character.MAX_VALUE + 1);
572 int negatedCharacters = DISTINCT_CHARS - totalCharacters;
573 String suffix = ".negate()";
574 final String description = toString();
575 String negatedDescription =
576 description.endsWith(suffix)
577 ? description.substring(0, description.length() - suffix.length())
578 : description + suffix;
579 return new NegatedFastMatcher(precomputedPositive(negatedCharacters, table, negatedDescription)) {
580 @Override
581 public String toString() {
582 return description;
583 }
584 };
585 }
586 }
587
588 /**
589 * Helper method for {@link #precomputedInternal} that doesn't test if the negation is cheaper.

Callers 1

precomputeCharMatcherMethod · 0.45

Calls 5

setBitsMethod · 0.95
precomputedPositiveMethod · 0.95
toStringMethod · 0.95
flipMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected