Choose algorithms and data structures that provide both deterministic behavior and optimal performance characteristics. Prefer ordered collections when iteration order matters, optimize pattern matching to avoid expensive operations, and be mindful of algorithmic complexity.
Key principles:
std::set
instead of unsorted_set
, ImmutableListMultimap
instead of custom maps) to ensure consistent outputindexOf
) over regex patterns for simple substring matchingExample optimization:
// Instead of complex regex for simple suffix matching
if (LITERAL_PATTERN_WITH_DOT_UNESCAPED.matcher(suffixPattern).matches()) {
String literalSuffix = suffixPattern.replace("\\.", ".");
return s -> s.endsWith(literalSuffix); // Much faster than regex
}
// Use ordered collections for deterministic behavior
ImmutableListMultimap<Label, SpawnStrategy> platformToStrategies; // Preserves order
// Instead of: Map<Label, List<SpawnStrategy>>
This approach ensures both correctness through deterministic behavior and performance through algorithmic efficiency.
Enter the URL of a public GitHub repository