From 606a77ca29405b42e580051ea74fe6f75d311179 Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Sat, 2 Feb 2008 22:14:23 +0000 Subject: [PATCH] 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 --- ChangeLog | 9 +++++++++ libsoup/Makefile.am | 1 + libsoup/soup-method.c | 27 +++++++++++++++++++++++++ libsoup/soup-method.h | 56 +++++++++++++++++++++++++++++++++++---------------- libsoup/soup-uri.c | 21 +++++++++---------- libsoup/soup-uri.h | 5 +++-- 6 files changed, 88 insertions(+), 31 deletions(-) create mode 100644 libsoup/soup-method.c diff --git a/ChangeLog b/ChangeLog index 033bde7..2a30fb1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2008-02-02 Dan Winship + + * 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 * libsoup/soup-address.c: Use GObject properties. diff --git a/libsoup/Makefile.am b/libsoup/Makefile.am index 571413f..8c342d5 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 0000000..6c5c3dd --- /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 +#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 861f7ef..4074d07 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 * **/ -#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 deeb4d5..36ccf17 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 34a9457..f13fa19 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); -- 2.7.4