Skip to content

Commit ffbaa58

Browse files
committed
bestCppStd: cache result per binary, avoid repeated g++ probe
1 parent 695cc43 commit ffbaa58

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

mode/CppMode.jar

181 Bytes
Binary file not shown.

src/java/CppBuild.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2998,9 +2998,12 @@ private List<String> wordWrap(String line, int max) {
29982998
return r;
29992999
}
30003000

3001-
/** Returns the best -std=c++XX flag supported by the given g++ binary. */
3001+
/** Returns the best -std=c++XX flag supported by the given g++ binary. Cached per binary. */
3002+
private static final java.util.concurrent.ConcurrentHashMap<String,String> _stdCache
3003+
= new java.util.concurrent.ConcurrentHashMap<>();
30023004
static String bestCppStd(String gpp) {
3003-
for (String std : new String[]{"c++2c", "c++23", "c++20", "c++17"}) {
3005+
return _stdCache.computeIfAbsent(gpp, g -> {
3006+
for (String std : new String[]{"c++2c", "c++23", "c++20", "c++17"}) {
30043007
try {
30053008
ProcessBuilder pb = new ProcessBuilder(gpp, "-std=" + std, "-x", "c++", "-fsyntax-only", "-");
30063009
pb.redirectErrorStream(true);
@@ -3013,7 +3016,8 @@ static String bestCppStd(String gpp) {
30133016
}
30143017
} catch (Exception ignored) {}
30153018
}
3016-
return "c++17";
3019+
return "c++17";
3020+
});
30173021
}
30183022

30193023
private List<String> buildCommand(String gpp, File src, File bin, boolean win, boolean mac) {

0 commit comments

Comments
 (0)