Skip to content

Commit

Permalink
cache libBasePath
Browse files Browse the repository at this point in the history
  • Loading branch information
m0rkeulv committed Jul 14, 2023
1 parent 1810dc2 commit 693c144
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1280,6 +1280,7 @@ public boolean setDirty(boolean newState) {
// the project settings really changed, and act accordingly.
myCache.clear();
myLibraryCacheManager.clear();
HaxelibUtil.clearCache();
}
}
return ret;
Expand Down
26 changes: 25 additions & 1 deletion src/main/java/com/intellij/plugins/haxe/haxelib/HaxelibUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@
public class HaxelibUtil {
static public final String LOCAL_REPO = ".haxelib";

static private Map<String,String> libBasePathCache = new HashMap<>();
public static void clearCache() {
libBasePathCache.clear();
}

static { // Take this out when finished debugging.
log.setLevel(LogLevel.DEBUG);
}
Expand All @@ -67,19 +72,38 @@ public class HaxelibUtil {

/**
* Get the base path that haxelib uses to store libraries.
*
* note: We attempt to cache results as libBasePath is more or less haxelib repo dir (global or local)
*
* @param sdk
* @return
*/
@Nullable
public static VirtualFile getLibraryBasePath(@NotNull final Sdk sdk, VirtualFile workDir) {
String workDirPath = workDir.getCanonicalPath();
VirtualFile file = null;
if (libBasePathCache.containsKey(workDirPath)) {
String libBasePath = libBasePathCache.get(workDirPath);
file = LocalFileSystem.getInstance().findFileByPath(libBasePath);
}else{
file = _getLibraryBasePath(sdk, workDir);
if(file!= null) {
String path = file.getCanonicalPath();
libBasePathCache.put(workDirPath, path);
}
}
return file;
}
@Nullable
private static VirtualFile _getLibraryBasePath(@NotNull final Sdk sdk, VirtualFile workDir) {
List<String> output = HaxelibCommandUtils.issueHaxelibCommand(sdk, workDir, "config");
for (String s : output) {
if (s.isEmpty()) continue;
VirtualFile file = LocalFileSystem.getInstance().findFileByPath(s);
if (null != file) {
return file;
}
}
}
return null;
}

Expand Down

0 comments on commit 693c144

Please sign in to comment.