Skip to content

Commit 0b8f319

Browse files
committed
optimize find func
1 parent 381819a commit 0b8f319

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

src/EIDEProject.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1640,7 +1640,7 @@ export abstract class AbstractProject implements CustomConfigurationProvider, Pr
16401640
.forEach(f => platform.DeleteDir(f));
16411641
}
16421642

1643-
this.GetConfiguration().BuildIn_AddAllFromDefineList(libPaths);
1643+
this.GetConfiguration().CustomDep_AddAllFromLibList(libPaths);
16441644

16451645
doneList.push(rePath);
16461646
}

src/Platform.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,20 +229,31 @@ export function DeleteAllChildren(dir: File): string {
229229
}
230230
}
231231

232-
export function find(fileName: string): string | undefined {
232+
const __find_cache: Map<string, string> = new Map();
233+
export function find(fileName: string, refreshCache?: boolean): string | undefined {
234+
235+
if (refreshCache)
236+
__find_cache.delete(fileName);
237+
238+
if (__find_cache.has(fileName))
239+
return __find_cache.get(fileName);
240+
233241
try {
234242
if (osPlatform == 'win32') {
235243
const nameList = child_process.execSync(`where "${fileName}"`,
236-
{ windowsHide: true, encoding: 'ascii', shell: 'cmd' }).split(/\r\n|\n/);
244+
{ windowsHide: true, encoding: 'ascii', shell: 'cmd' }).toString().trim().split(/\r\n|\n/);
237245
if (nameList.length > 0) {
238246
const path = nameList[0].replace(/"/g, '');
239247
if (File.isAbsolute(path)) {
248+
__find_cache.set(fileName, path);
240249
return path;
241250
}
242251
}
243252
} else {
244253
const res = child_process.execSync(`which ${fileName}`).toString().trim();
245-
return res.replace(/"'/g, '');
254+
const path = res.replace(/"'/g, '');
255+
__find_cache.set(fileName, path);
256+
return path;
246257
}
247258
} catch (error) {
248259
return undefined;

0 commit comments

Comments
 (0)