aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohan Liesén2012-09-06 10:35:53 +0200
committerJohan Liesén2012-09-06 10:45:13 +0200
commitcf5d98a8cadff87a54ffbf3fc55dbff4b12831bc (patch)
treec3b2a641a261b94031224dc4c8f004dbbc0ec6b1
parent560ceb7828a1911f6227f36180726094f8e7fbfa (diff)
downloadvimium-cf5d98a8cadff87a54ffbf3fc55dbff4b12831bc.tar.bz2
Move instant tests to the top of the function: return early if possible
-rw-r--r--lib/utils.coffee12
1 files changed, 6 insertions, 6 deletions
diff --git a/lib/utils.coffee b/lib/utils.coffee
index 00dce5b4..49481445 100644
--- a/lib/utils.coffee
+++ b/lib/utils.coffee
@@ -45,6 +45,12 @@ Utils =
# Tries to detect if :str is a valid URL.
isUrl: (str) ->
+ # Starts with a scheme: URL
+ return true if /^[a-z]{3,}:\/\//.test str
+
+ # Must not contain spaces
+ return false if ' ' in str
+
# More or less RFC compliant URL host part parsing. This should be sufficient for our needs
urlRegex = new RegExp(
'^(?:([^:]+)(?::([^:]+))?@)?' + # user:password (optional) => \1, \2
@@ -57,12 +63,6 @@ Utils =
specialHostNames = ['localhost']
- # Starts with a scheme: URL
- return true if /^[a-z]{3,}:\/\//.test str
-
- # Must not contain spaces
- return false if ' ' in str
-
# Try to parse the URL into its meaningful parts. If matching fails we're pretty sure that we don't have
# some kind of URL here.
match = urlRegex.exec (str.split '/')[0]