Remove unnecessary options parser caching.
The options parser already has a static cache of all the reflection work performed. There can still be costs associated with the obtaining and combining of options classes (see the BlazeCommandDispatcher's additional caching), but in this case, each parser is made with a single options class, and none of the class-name extraction was being cached, so I think there was nothing gained.
RELNOTES: None.
PiperOrigin-RevId: 165613107
diff --git a/src/main/java/com/google/devtools/build/lib/rules/config/ConfigSetting.java b/src/main/java/com/google/devtools/build/lib/rules/config/ConfigSetting.java
index afea25b..b45e11b 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/config/ConfigSetting.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/config/ConfigSetting.java
@@ -52,7 +52,6 @@
import com.google.devtools.common.options.OptionsParser;
import com.google.devtools.common.options.OptionsParsingException;
import java.util.Collection;
-import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -161,9 +160,6 @@
// make sure to examine only the value we just parsed: not the entire list.
Multiset<String> optionsCount = HashMultiset.create();
- // Since OptionsParser instantiation involves reflection, let's try to minimize that happening.
- Map<Class<? extends OptionsBase>, OptionsParser> parserCache = new HashMap<>();
-
for (Map.Entry<String, String> setting : expectedSettings) {
String optionName = setting.getKey();
String expectedRawValue = setting.getValue();
@@ -178,10 +174,9 @@
continue;
}
- OptionsParser parser =
- parserCache.computeIfAbsent(optionClass, OptionsParser::newOptionsParser);
-
+ OptionsParser parser;
try {
+ parser = OptionsParser.newOptionsParser(optionClass);
parser.parse("--" + optionName + "=" + expectedRawValue);
} catch (OptionsParsingException ex) {
errors.attributeError(