diff options
author | Benjamin Otte <otte@gnome.org> | 2009-07-03 20:13:57 +0800 |
---|---|---|
committer | Benjamin Otte <otte@gnome.org> | 2009-07-06 03:40:44 +0800 |
commit | a464b7332c02f6b4e34c5a7a88b8b93198f3e9be (patch) | |
tree | 29675fa45a8b48e2f18e6682480f4e000af1e1c8 /src/ephy-completion-model.c | |
parent | da229480300ab899a825e4bb23c3497a5c00f8e7 (diff) | |
download | gsoc2013-epiphany-a464b7332c02f6b4e34c5a7a88b8b93198f3e9be.tar gsoc2013-epiphany-a464b7332c02f6b4e34c5a7a88b8b93198f3e9be.tar.gz gsoc2013-epiphany-a464b7332c02f6b4e34c5a7a88b8b93198f3e9be.tar.bz2 gsoc2013-epiphany-a464b7332c02f6b4e34c5a7a88b8b93198f3e9be.tar.lz gsoc2013-epiphany-a464b7332c02f6b4e34c5a7a88b8b93198f3e9be.tar.xz gsoc2013-epiphany-a464b7332c02f6b4e34c5a7a88b8b93198f3e9be.tar.zst gsoc2013-epiphany-a464b7332c02f6b4e34c5a7a88b8b93198f3e9be.zip |
compute base address with strchr and without regexps
This fixes two problems:
1) It improves performance a lot.
2) The regexp in use was not strict enough. It happily matched non-base
addresses. (i.e. http://example.com/your-mom/ )
Diffstat (limited to 'src/ephy-completion-model.c')
-rw-r--r-- | src/ephy-completion-model.c | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/src/ephy-completion-model.c b/src/ephy-completion-model.c index d0dbda345..6f4c3ccb5 100644 --- a/src/ephy-completion-model.c +++ b/src/ephy-completion-model.c @@ -20,6 +20,8 @@ #include "config.h" +#include <string.h> + #include "ephy-completion-model.h" #include "ephy-favicon-cache.h" #include "ephy-node.h" @@ -347,14 +349,29 @@ const GRegex *base_address_regex = NULL; static gboolean is_base_address (const char *address) { - if (base_address_regex == NULL) { - base_address_regex = g_regex_new ("//.*/$", - G_REGEX_OPTIMIZE, - G_REGEX_MATCH_NOTEMPTY, - NULL); - } - - return g_regex_match (base_address_regex, address, G_REGEX_MATCH_NOTEMPTY, NULL); + if (address == NULL) + return FALSE; + + /* a base address is <scheme>://<host>/ + * Neither scheme nor host contain a slash, so we can use slashes + * figure out if it's a base address. + * + * Note: previous code was using a GRegExp to do the same thing. + * While regexps are much nicer to read, they're also a lot + * slower. + */ + address = strchr (address, '/'); + if (address == NULL || + address[1] != '/') + return FALSE; + + address += 2; + address = strchr (address, '/'); + if (address == NULL || + address[1] != 0) + return FALSE; + + return TRUE; } static void |