Chromium Code Reviews| Index: sdk/lib/io/platform_impl.dart |
| diff --git a/sdk/lib/io/platform_impl.dart b/sdk/lib/io/platform_impl.dart |
| index 40fe2f0cf79a7b557d2dfa1c3385262426fd1c19..f66123c1ec478bc0e4f259a510b7d86f7c753f49 100644 |
| --- a/sdk/lib/io/platform_impl.dart |
| +++ b/sdk/lib/io/platform_impl.dart |
| @@ -15,6 +15,10 @@ class _Platform { |
| external static String _packageRoot(); |
| external static String _version(); |
| + // Cache the OS environemnt. This can be an OSError instance if |
| + // retrieving the environment failed. |
| + static var _environmentCache; |
| + |
| static int get numberOfProcessors => _numberOfProcessors(); |
| static String get pathSeparator => _pathSeparator(); |
| static String get operatingSystem => _operatingSystem(); |
| @@ -45,28 +49,36 @@ class _Platform { |
| static List<String> get executableArguments => _executableArguments(); |
| static Map<String, String> get environment { |
| - var env = _environment(); |
| - if (env is OSError) { |
| - throw env; |
| - } else { |
| - var isWindows = operatingSystem == 'windows'; |
| - var result = isWindows ? new _CaseInsensitiveStringMap() : new Map(); |
| - for (var str in env) { |
| - // When running on Windows through cmd.exe there are strange |
| - // environment variables that are used to record the current |
| - // working directory for each drive and the exit code for the |
| - // last command. As an example: '=A:=A:\subdir' records the |
| - // current working directory on the 'A' drive. In order to |
| - // handle these correctly we search for a second occurrence of |
| - // of '=' in the string if the first occurrence is at index 0. |
| - var equalsIndex = str.indexOf('='); |
| - if (equalsIndex == 0) { |
| - equalsIndex = str.indexOf('=', 1); |
| + if (_environmentCache == null) { |
| + var env = _environment(); |
| + if (env is !OSError) { |
| + var isWindows = operatingSystem == 'windows'; |
| + var result = isWindows ? new _CaseInsensitiveStringMap() : new Map(); |
| + for (var str in env) { |
| + // When running on Windows through cmd.exe there are strange |
| + // environment variables that are used to record the current |
| + // working directory for each drive and the exit code for the |
| + // last command. As an example: '=A:=A:\subdir' records the |
| + // current working directory on the 'A' drive. In order to |
| + // handle these correctly we search for a second occurrence of |
| + // of '=' in the string if the first occurrence is at index 0. |
| + var equalsIndex = str.indexOf('='); |
| + if (equalsIndex == 0) { |
| + equalsIndex = str.indexOf('=', 1); |
| + } |
| + assert(equalsIndex != -1); |
| + result[str.substring(0, equalsIndex)] = str.substring(equalsIndex + 1); |
|
Anders Johnsen
2014/01/05 20:41:21
Long line.
Søren Gjesse
2014/01/06 10:17:32
Done.
|
| } |
| - assert(equalsIndex != -1); |
| - result[str.substring(0, equalsIndex)] = str.substring(equalsIndex + 1); |
| + _environmentCache = new _UnmodifiableMap(result); |
| + } else { |
| + _environmentCache = env; |
| } |
| - return result; |
| + } |
| + |
| + if (_environmentCache is OSError) { |
| + throw _environmentCache; |
| + } else { |
| + return _environmentCache; |
| } |
| } |