MCPcopy Index your code
hub / github.com/antlr/codebuff / precomputedInternal

Method precomputedInternal

output/java_guava/1.4.19/CharMatcher.java:563–588  ·  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

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

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected