diff options
author | Andrey Loskutov <loskutov@gmx.de> | 2015-09-10 00:04:38 +0200 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2015-09-27 02:04:57 +0200 |
commit | 41a972cd1efe22ba65b4dfdd2fcaad8af18a522c (patch) | |
tree | f8c8c8baf0a17e5589d84d14cf247adbef3a08fe /org.eclipse.jgit/src/org/eclipse/jgit/util | |
parent | 1abd51d95373fcf7450463478b45aa7da8012cef (diff) | |
download | jgit-41a972cd1efe22ba65b4dfdd2fcaad8af18a522c.tar.gz jgit-41a972cd1efe22ba65b4dfdd2fcaad8af18a522c.zip |
[performance] Cache platform name in SystemReader
SystemReader.isMacOs() and SystemReader.isWindows() return values are
unlikely to change during the JVM lifetime (except tests). Don't read
system properties each time the methods are called, just use previously
calculated value.
Change-Id: I495521f67a8b544e7b7247d99bbd05a42ea16d20
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/util')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/util/SystemReader.java | 40 |
1 files changed, 26 insertions, 14 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/SystemReader.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/SystemReader.java index b4233b6ccd..4795c89e73 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/SystemReader.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/SystemReader.java @@ -71,6 +71,11 @@ import org.eclipse.jgit.lib.ObjectChecker; */ public abstract class SystemReader { private static final SystemReader DEFAULT; + + private static Boolean isMacOS; + + private static Boolean isWindows; + static { SystemReader r = new Default(); r.init(); @@ -148,6 +153,8 @@ public abstract class SystemReader { * the default instance. */ public static void setInstance(SystemReader newReader) { + isMacOS = null; + isWindows = null; if (newReader == null) INSTANCE = DEFAULT; else { @@ -293,26 +300,31 @@ public abstract class SystemReader { * @return true if we are running on a Windows. */ public boolean isWindows() { - String osDotName = AccessController - .doPrivileged(new PrivilegedAction<String>() { - public String run() { - return getProperty("os.name"); //$NON-NLS-1$ - } - }); - return osDotName.startsWith("Windows"); //$NON-NLS-1$ + if (isWindows == null) { + String osDotName = getOsName(); + isWindows = Boolean.valueOf(osDotName.startsWith("Windows")); //$NON-NLS-1$ + } + return isWindows.booleanValue(); } /** * @return true if we are running on Mac OS X */ public boolean isMacOS() { - String osDotName = AccessController - .doPrivileged(new PrivilegedAction<String>() { - public String run() { - return getProperty("os.name"); //$NON-NLS-1$ - } - }); - return "Mac OS X".equals(osDotName) || "Darwin".equals(osDotName); //$NON-NLS-1$ //$NON-NLS-2$ + if (isMacOS == null) { + String osDotName = getOsName(); + isMacOS = Boolean.valueOf( + "Mac OS X".equals(osDotName) || "Darwin".equals(osDotName)); //$NON-NLS-1$ //$NON-NLS-2$ + } + return isMacOS.booleanValue(); + } + + private String getOsName() { + return AccessController.doPrivileged(new PrivilegedAction<String>() { + public String run() { + return getProperty("os.name"); //$NON-NLS-1$ + } + }); } /** |