summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Winship <danw@src.gnome.org>2008-02-02 22:14:23 +0000
committerDan Winship <danw@src.gnome.org>2008-02-02 22:14:23 +0000
commit606a77ca29405b42e580051ea74fe6f75d311179 (patch)
treeaad30c8685d888f8e52496e138c5641aac40138d
parent87dff5a5be45fd038f2ec4e0b19599ef734ef5e2 (diff)
downloadlibsoup-606a77ca29405b42e580051ea74fe6f75d311179.tar.gz
Fix these so that direct comparisons against them actually *are* faster
* libsoup/soup-method.h (SOUP_METHOD_GET, etc): Fix these so that direct comparisons against them actually *are* faster than doing strcmp, as the docs claim. * libsoup/soup-uri.h (SOUP_URI_SCHEME_HTTP, SOUP_URI_SCHEME_HTTPS): likewise svn path=/trunk/; revision=1068
-rw-r--r--ChangeLog9
-rw-r--r--libsoup/Makefile.am1
-rw-r--r--libsoup/soup-method.c27
-rw-r--r--libsoup/soup-method.h56
-rw-r--r--libsoup/soup-uri.c21
-rw-r--r--libsoup/soup-uri.h5
6 files changed, 88 insertions, 31 deletions
diff --git a/ChangeLog b/ChangeLog
index 033bde73..2a30fb1a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2008-02-02 Dan Winship <danw@gnome.org>
+
+ * libsoup/soup-method.h (SOUP_METHOD_GET, etc): Fix these so that
+ direct comparisons against them actually *are* faster than doing
+ strcmp, as the docs claim.
+
+ * libsoup/soup-uri.h (SOUP_URI_SCHEME_HTTP,
+ SOUP_URI_SCHEME_HTTPS): likewise
+
2008-02-01 Dan Winship <danw@gnome.org>
* libsoup/soup-address.c: Use GObject properties.
diff --git a/libsoup/Makefile.am b/libsoup/Makefile.am
index 571413fb..8c342d50 100644
--- a/libsoup/Makefile.am
+++ b/libsoup/Makefile.am
@@ -126,6 +126,7 @@ libsoup_2_4_la_SOURCES = \
soup-message-queue.h \
soup-message-queue.c \
soup-message-server-io.c \
+ soup-method.c \
soup-misc.c \
soup-nossl.c \
soup-path-map.h \
diff --git a/libsoup/soup-method.c b/libsoup/soup-method.c
new file mode 100644
index 00000000..6c5c3dd3
--- /dev/null
+++ b/libsoup/soup-method.c
@@ -0,0 +1,27 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * soup-method.c: declarations of _SOUP_METHOD_* variables
+ *
+ * Copyright (C) 2008 Red Hat, Inc.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+const char *_SOUP_METHOD_CONNECT;
+const char *_SOUP_METHOD_COPY;
+const char *_SOUP_METHOD_DELETE;
+const char *_SOUP_METHOD_GET;
+const char *_SOUP_METHOD_HEAD;
+const char *_SOUP_METHOD_LOCK;
+const char *_SOUP_METHOD_MKCOL;
+const char *_SOUP_METHOD_MOVE;
+const char *_SOUP_METHOD_OPTIONS;
+const char *_SOUP_METHOD_PATCH;
+const char *_SOUP_METHOD_POST;
+const char *_SOUP_METHOD_PROPFIND;
+const char *_SOUP_METHOD_PROPPATCH;
+const char *_SOUP_METHOD_PUT;
+const char *_SOUP_METHOD_TRACE;
+const char *_SOUP_METHOD_UNLOCK;
diff --git a/libsoup/soup-method.h b/libsoup/soup-method.h
index 861f7ef1..4074d073 100644
--- a/libsoup/soup-method.h
+++ b/libsoup/soup-method.h
@@ -1,6 +1,6 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
- * Copyright (C) 2001-2002, Ximian, Inc.
+ * Copyright (C) 2008 Red Hat, Inc.
*/
#ifndef SOUP_METHOD_H
@@ -31,22 +31,44 @@ G_BEGIN_DECLS
* </programlisting></informalexample>
**/
-#define SOUP_METHOD_POST (g_intern_static_string ("POST"))
-#define SOUP_METHOD_GET (g_intern_static_string ("GET"))
-#define SOUP_METHOD_HEAD (g_intern_static_string ("HEAD"))
-#define SOUP_METHOD_OPTIONS (g_intern_static_string ("OPTIONS"))
-#define SOUP_METHOD_PUT (g_intern_static_string ("PUT"))
-#define SOUP_METHOD_MOVE (g_intern_static_string ("MOVE"))
-#define SOUP_METHOD_COPY (g_intern_static_string ("COPY"))
-#define SOUP_METHOD_DELETE (g_intern_static_string ("DELETE"))
-#define SOUP_METHOD_TRACE (g_intern_static_string ("TRACE"))
-#define SOUP_METHOD_CONNECT (g_intern_static_string ("CONNECT"))
-#define SOUP_METHOD_MKCOL (g_intern_static_string ("MKCOL"))
-#define SOUP_METHOD_PROPPATCH (g_intern_static_string ("PROPPATCH"))
-#define SOUP_METHOD_PROPFIND (g_intern_static_string ("PROPFIND"))
-#define SOUP_METHOD_PATCH (g_intern_static_string ("PATCH"))
-#define SOUP_METHOD_LOCK (g_intern_static_string ("LOCK"))
-#define SOUP_METHOD_UNLOCK (g_intern_static_string ("UNLOCK"))
+/* HTTP/1.1 methods */
+#define SOUP_METHOD_OPTIONS (_SOUP_METHOD_OPTIONS ? _SOUP_METHOD_OPTIONS : (_SOUP_METHOD_OPTIONS = g_intern_static_string ("OPTIONS")))
+#define SOUP_METHOD_GET (_SOUP_METHOD_GET ? _SOUP_METHOD_GET : (_SOUP_METHOD_GET = g_intern_static_string ("GET")))
+#define SOUP_METHOD_HEAD (_SOUP_METHOD_HEAD ? _SOUP_METHOD_HEAD : (_SOUP_METHOD_HEAD = g_intern_static_string ("HEAD")))
+#define SOUP_METHOD_POST (_SOUP_METHOD_POST ? _SOUP_METHOD_POST : (_SOUP_METHOD_POST = g_intern_static_string ("POST")))
+#define SOUP_METHOD_PUT (_SOUP_METHOD_PUT ? _SOUP_METHOD_PUT : (_SOUP_METHOD_PUT = g_intern_static_string ("PUT")))
+#define SOUP_METHOD_DELETE (_SOUP_METHOD_DELETE ? _SOUP_METHOD_DELETE : (_SOUP_METHOD_DELETE = g_intern_static_string ("DELETE")))
+#define SOUP_METHOD_TRACE (_SOUP_METHOD_TRACE ? _SOUP_METHOD_TRACE : (_SOUP_METHOD_TRACE = g_intern_static_string ("TRACE")))
+#define SOUP_METHOD_CONNECT (_SOUP_METHOD_CONNECT ? _SOUP_METHOD_CONNECT : (_SOUP_METHOD_CONNECT = g_intern_static_string ("CONNECT")))
+
+/* WebDAV methods */
+#define SOUP_METHOD_PROPFIND (_SOUP_METHOD_PROPFIND ? _SOUP_METHOD_PROPFIND : (_SOUP_METHOD_PROPFIND = g_intern_static_string ("PROPFIND")))
+#define SOUP_METHOD_PROPPATCH (_SOUP_METHOD_PROPPATCH ? _SOUP_METHOD_PROPPATCH : (_SOUP_METHOD_PROPPATCH = g_intern_static_string ("PROPPATCH")))
+#define SOUP_METHOD_MKCOL (_SOUP_METHOD_MKCOL ? _SOUP_METHOD_MKCOL : (_SOUP_METHOD_MKCOL = g_intern_static_string ("MKCOL")))
+#define SOUP_METHOD_COPY (_SOUP_METHOD_COPY ? _SOUP_METHOD_COPY : (_SOUP_METHOD_COPY = g_intern_static_string ("COPY")))
+#define SOUP_METHOD_MOVE (_SOUP_METHOD_MOVE ? _SOUP_METHOD_MOVE : (_SOUP_METHOD_MOVE = g_intern_static_string ("MOVE")))
+#define SOUP_METHOD_LOCK (_SOUP_METHOD_LOCK ? _SOUP_METHOD_LOCK : (_SOUP_METHOD_LOCK = g_intern_static_string ("LOCK")))
+#define SOUP_METHOD_UNLOCK (_SOUP_METHOD_UNLOCK ? _SOUP_METHOD_UNLOCK : (_SOUP_METHOD_UNLOCK = g_intern_static_string ("UNLOCK")))
+
+/* Do not use these variables directly; use the macros above, which
+ * ensure that they get initialized properly.
+ */
+extern const char *_SOUP_METHOD_OPTIONS;
+extern const char *_SOUP_METHOD_GET;
+extern const char *_SOUP_METHOD_HEAD;
+extern const char *_SOUP_METHOD_POST;
+extern const char *_SOUP_METHOD_PUT;
+extern const char *_SOUP_METHOD_DELETE;
+extern const char *_SOUP_METHOD_TRACE;
+extern const char *_SOUP_METHOD_CONNECT;
+
+extern const char *_SOUP_METHOD_PROPFIND;
+extern const char *_SOUP_METHOD_PROPPATCH;
+extern const char *_SOUP_METHOD_MKCOL;
+extern const char *_SOUP_METHOD_COPY;
+extern const char *_SOUP_METHOD_MOVE;
+extern const char *_SOUP_METHOD_LOCK;
+extern const char *_SOUP_METHOD_UNLOCK;
G_END_DECLS
diff --git a/libsoup/soup-uri.c b/libsoup/soup-uri.c
index deeb4d5c..36ccf174 100644
--- a/libsoup/soup-uri.c
+++ b/libsoup/soup-uri.c
@@ -81,19 +81,15 @@ static void append_uri_encoded (GString *str, const char *in, const char *extra_
static char *uri_decoded_copy (const char *str, int length);
static char *uri_normalized_copy (const char *str, int length, const char *unescape_extra);
-static const char *http_scheme, *https_scheme;
+const char *_SOUP_URI_SCHEME_HTTP, *_SOUP_URI_SCHEME_HTTPS;
static inline const char *
soup_uri_get_scheme (const char *scheme, int len)
{
if (len == 4 && !strncmp (scheme, "http", 4)) {
- if (G_UNLIKELY (!http_scheme))
- http_scheme = g_intern_static_string ("http");
- return http_scheme;
+ return SOUP_URI_SCHEME_HTTP;
} else if (len == 5 && !strncmp (scheme, "https", 5)) {
- if (G_UNLIKELY (!https_scheme))
- https_scheme = g_intern_static_string ("https");
- return https_scheme;
+ return SOUP_URI_SCHEME_HTTPS;
} else {
char *lower_scheme;
@@ -107,9 +103,9 @@ soup_uri_get_scheme (const char *scheme, int len)
static inline guint
soup_scheme_default_port (const char *scheme)
{
- if (scheme == http_scheme)
+ if (scheme == SOUP_URI_SCHEME_HTTP)
return 80;
- else if (scheme == https_scheme)
+ else if (scheme == SOUP_URI_SCHEME_HTTPS)
return 443;
else
return 0;
@@ -339,7 +335,8 @@ soup_uri_new_with_base (SoupURI *base, const char *uri_string)
}
/* HTTP-specific stuff */
- if (uri->scheme == http_scheme || uri->scheme == https_scheme) {
+ if (uri->scheme == SOUP_URI_SCHEME_HTTP ||
+ uri->scheme == SOUP_URI_SCHEME_HTTPS) {
if (!uri->host) {
soup_uri_free (uri);
return NULL;
@@ -754,8 +751,8 @@ soup_uri_normalize (const char *part, const char *unescape_extra)
gboolean
soup_uri_uses_default_port (SoupURI *uri)
{
- g_return_val_if_fail (uri->scheme == http_scheme ||
- uri->scheme == https_scheme, FALSE);
+ g_return_val_if_fail (uri->scheme == SOUP_URI_SCHEME_HTTP ||
+ uri->scheme == SOUP_URI_SCHEME_HTTPS, FALSE);
return uri->port == soup_scheme_default_port (uri->scheme);
}
diff --git a/libsoup/soup-uri.h b/libsoup/soup-uri.h
index 34a9457a..f13fa19b 100644
--- a/libsoup/soup-uri.h
+++ b/libsoup/soup-uri.h
@@ -30,8 +30,9 @@ struct SoupURI {
GType soup_uri_get_type (void);
#define SOUP_TYPE_URI (soup_uri_get_type ())
-#define SOUP_URI_SCHEME_HTTP (g_intern_static_string ("http"))
-#define SOUP_URI_SCHEME_HTTPS (g_intern_static_string ("https"))
+#define SOUP_URI_SCHEME_HTTP (_SOUP_URI_SCHEME_HTTP ? _SOUP_URI_SCHEME_HTTP : (_SOUP_URI_SCHEME_HTTP = g_intern_static_string ("http")))
+#define SOUP_URI_SCHEME_HTTPS (_SOUP_URI_SCHEME_HTTPS ? _SOUP_URI_SCHEME_HTTPS : (_SOUP_URI_SCHEME_HTTPS = g_intern_static_string ("https")))
+extern const char *_SOUP_URI_SCHEME_HTTP, *_SOUP_URI_SCHEME_HTTPS;
SoupURI *soup_uri_new_with_base (SoupURI *base,
const char *uri_string);