Skip to content

Commit 7d9621e

Browse files
committed
Optimization: don't scan for runner on .NET Framework
1 parent 5eb62c2 commit 7d9621e

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/core/IronPython/Hosting/PythonCommandLine.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,12 @@ private void InitializeModules() {
313313

314314
PythonContext.SetHostVariables(prefix ?? "", executable, null);
315315

316-
// --------
316+
317+
// --- Local functions -------
318+
317319
static bool FindRunner(string prefix, string name, string assembly, out string runner) {
318320
runner = null;
321+
#if NET
319322
while (prefix != null) {
320323
runner = Path.Combine(prefix, name);
321324
if (File.Exists(runner)) {
@@ -336,32 +339,32 @@ static bool FindRunner(string prefix, string name, string assembly, out string r
336339
using var accessor = mmf.CreateViewAccessor(0, 0, MemoryMappedFileAccess.Read);
337340

338341
for (long i = accessor.Capacity - fsAssemblyPath.Length; i >= 0; i--) { // the path should be close to the end of the file
339-
if (accessor.ReadByte(i) != fsap0) {
340-
continue;
341-
}
342+
if (accessor.ReadByte(i) != fsap0) continue;
343+
342344
bool found = true;
343345
for (int j = 1; j < fsAssemblyPath.Length; j++) {
344346
if (accessor.ReadByte(i + j) != fsAssemblyPath[j]) {
345347
found = false;
346348
break;
347349
}
348350
}
349-
if (found) {
350-
return true;
351-
}
351+
if (found) return true;
352352
}
353353
} catch { }
354354
}
355+
#endif
355356
return false;
356357
}
357358

359+
#if NET
358360
[UnsupportedOSPlatform("windows")]
359361
static bool IsExecutable(string filePath) {
360362
var fileInfo = new Mono.Unix.UnixFileInfo(filePath);
361363
var fileMode = fileInfo.FileAccessPermissions;
362364

363365
return (fileMode & (Mono.Unix.FileAccessPermissions.UserExecute | Mono.Unix.FileAccessPermissions.GroupExecute | Mono.Unix.FileAccessPermissions.OtherExecute)) != 0;
364366
}
367+
#endif
365368
}
366369

367370
/// <summary>

0 commit comments

Comments
 (0)