Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ExecutionEnvironment to cache command line #680

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions source/VersionHandlerImpl/src/ExecutionEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,43 @@ namespace Google {
/// </summary>
internal class ExecutionEnvironment {

/// <summary>
/// Cached lower case CommandLine
/// </summary>
private static string Cached_Environment_CommandLine_Lower = null;
Copy link

@Tommigun1980 Tommigun1980 Oct 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a constant so name should not use underscore notation.


/// <summary>
/// Get/Set cached lower case CommandLine
/// </summary>
public static string Environment_CommandLine_Lower {
get {
if (Cached_Environment_CommandLine_Lower == null) {
Cached_Environment_CommandLine_Lower = Environment.CommandLine.ToLower();
}
return Cached_Environment_CommandLine_Lower;
}
}

/// <summary>
/// Whether the editor was started in batch mode.
/// </summary>
public static bool InBatchMode {
get { return Environment.CommandLine.ToLower().Contains("-batchmode"); }
get { return Environment_CommandLine_Lower.Contains("-batchmode"); }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is better than before but couldn't you just read all three of the switches it's interested in inside a constructor and just return booleans in the properties? This still runs unnecessary string operations every frame.

}

/// <summary>
/// Whether the editor was started with a method to executed.
/// </summary>
public static bool ExecuteMethodEnabled {
get { return Environment.CommandLine.ToLower().Contains("-executemethod"); }
get { return Environment_CommandLine_Lower.Contains("-executemethod"); }
}

/// <summary>
/// Whether the UI should be treated as interactive.
/// </summary>
internal static bool InteractiveMode {
get {
return !(Environment.CommandLine.ToLower().Contains("-gvh_noninteractive") ||
return !(Environment_CommandLine_Lower.Contains("-gvh_noninteractive") ||
ExecutionEnvironment.InBatchMode);
}
}
Expand Down