[epiphany] compute base address with strchr and without regexps



commit a464b7332c02f6b4e34c5a7a88b8b93198f3e9be
Author: Benjamin Otte <otte gnome org>
Date:   Fri Jul 3 14:13:57 2009 +0200

    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/ )

 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 d0dbda3..6f4c3cc 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



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]