aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorasie <kontakt@asie.pl>2019-11-05 09:56:17 -0800
committerKurt Alfred Kluever <kak@google.com>2019-11-06 15:18:21 -0500
commit989957df7e7fce1f025818e4ccd5a416636dcd51 (patch)
tree417e2a47c7202f832b2223a4f9d0cfe226d56a35
parent4fce17b2ff7e96cbd450c8ffc0d3560415779ce3 (diff)
downloadjimfs-989957df7e7fce1f025818e4ccd5a416636dcd51.tar.gz
fix Handler.getHostAddress() performance issue
Fixes #85 RELNOTES=n/a ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=278648767
-rw-r--r--jimfs/src/main/java/com/google/common/jimfs/Handler.java12
1 files changed, 12 insertions, 0 deletions
diff --git a/jimfs/src/main/java/com/google/common/jimfs/Handler.java b/jimfs/src/main/java/com/google/common/jimfs/Handler.java
index e5bfcbf..fd4ab74 100644
--- a/jimfs/src/main/java/com/google/common/jimfs/Handler.java
+++ b/jimfs/src/main/java/com/google/common/jimfs/Handler.java
@@ -19,6 +19,7 @@ package com.google.common.jimfs;
import static com.google.common.base.Preconditions.checkArgument;
import java.io.IOException;
+import java.net.InetAddress;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLStreamHandler;
@@ -77,4 +78,15 @@ public final class Handler extends URLStreamHandler {
protected URLConnection openConnection(URL url) throws IOException {
return new PathURLConnection(url);
}
+
+ @Override
+ @SuppressWarnings("UnsynchronizedOverridesSynchronized") // no need to synchronize to return null
+ protected InetAddress getHostAddress(URL url) {
+ // jimfs uses the URI host to specify the name of the file system being used.
+ // In the default implementation of getHostAddress(URL), a non-null host would cause an attempt
+ // to look up the IP address, causing a slowdown on calling equals/hashCode methods on the URL
+ // object. By returning null, we speed up equality checks on URL's (since there isn't an IP to
+ // connect to).
+ return null;
+ }
}