Skip to content

Commit b03bd7d

Browse files
committed
refactor ~ use late/lazy evaluation to avoid ENV{} and path.join() calls
## [why] There are a high number of ENV{} variable accesses and path manipulation calls for items which will only get very rare usage. These are replaced with functions with can be called late and lazily if/when higher priority items return undefined results.
1 parent c6e5443 commit b03bd7d

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/lib/OSPaths.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,18 @@ export function OSPathsAdaption_(adapter_: Platform.Adapter): OSPaths {
6363
const temp = () => {
6464
const fallback = 'C:\\Temp';
6565
const priorityList = [
66-
typeof os.tmpdir === 'function' ? os.tmpdir() : void 0,
67-
env.get('TEMP'),
68-
env.get('TMP'),
69-
joinPathToBase(env.get('LOCALAPPDATA'), ['Temp']),
70-
joinPathToBase(home(), ['AppData', 'Local', 'Temp']),
71-
joinPathToBase(env.get('ALLUSERSPROFILE'), ['Temp']),
72-
joinPathToBase(env.get('SystemRoot'), ['Temp']),
73-
joinPathToBase(env.get('windir'), ['Temp']),
74-
joinPathToBase(env.get('SystemDrive'), ['\\', 'Temp']),
66+
os.tmpdir,
67+
() => env.get('TEMP'),
68+
() => env.get('TMP'),
69+
() => joinPathToBase(env.get('LOCALAPPDATA'), ['Temp']),
70+
() => joinPathToBase(home(), ['AppData', 'Local', 'Temp']),
71+
() => joinPathToBase(env.get('ALLUSERSPROFILE'), ['Temp']),
72+
() => joinPathToBase(env.get('SystemRoot'), ['Temp']),
73+
() => joinPathToBase(env.get('windir'), ['Temp']),
74+
() => joinPathToBase(env.get('SystemDrive'), ['\\', 'Temp']),
7575
];
76-
return normalizePath(priorityList.find((v) => !isEmpty(v))) || fallback;
76+
const v = priorityList.find((v) => v && !isEmpty(v()));
77+
return (v && normalizePath(v())) || fallback;
7778
};
7879

7980
return { home, temp };

0 commit comments

Comments
 (0)