commit 04063e5afacfa876446857b8433d2f5445bdecf2 Author: Roger Leigh Date: Tue May 7 10:28:25 2013 +0100 Improve performance of Location constructor, by avoiding exception throwing when path is not an URL diff --git a/components/common/src/loci/common/Location.java b/components/common/src/loci/common/Location.java index 5c13302..dd65cb0 100644 --- a/components/common/src/loci/common/Location.java +++ b/components/common/src/loci/common/Location.java @@ -102,11 +102,17 @@ public class Location { public Location(String pathname) { LOGGER.trace("Location({})", pathname); - try { - url = new URL(getMappedId(pathname)); - } - catch (MalformedURLException e) { - LOGGER.trace("Location is not a URL", e); + if (pathname.contains("://")) { + // Avoid expensive exception handling in case when path is obviously not an URL + try { + url = new URL(getMappedId(pathname)); + } + catch (MalformedURLException e) { + LOGGER.trace("Location is not a URL", e); + isURL = false; + } + } else { + LOGGER.trace("Location is not a URL"); isURL = false; } if (!isURL) file = new File(getMappedId(pathname));