From c6f13db85878aeeaa7efd3894db88fe0d8a78168 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Mon, 31 Oct 2011 21:27:11 +0000 Subject: Don't need to generate string from scratch in nsurl_defragment, just copy. svn path=/trunk/netsurf/; revision=13103 --- utils/nsurl.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'utils') diff --git a/utils/nsurl.c b/utils/nsurl.c index 862797627..9978ded15 100644 --- a/utils/nsurl.c +++ b/utils/nsurl.c @@ -1736,13 +1736,14 @@ nserror nsurl_join(const nsurl *base, const char *rel, nsurl **joined) /* exported interface, documented in nsurl.h */ nserror nsurl_defragment(const nsurl *url, nsurl **no_frag) { - struct nsurl_component_lengths str_len = { 0, 0, 0, 0, 0, 0, 0, 0 }; - enum nsurl_string_flags str_flags = 0; size_t length; + char *pos; - /* Get the string length and find which parts of url are present */ - nsurl__get_string_data(&(url->components), NSURL_COMPLETE, &length, - &str_len, &str_flags); + /* Find the change in length from url to new_url */ + length = url->length; + if (url->components.fragment != NULL) { + length -= 1 + lwc_string_length(url->components.fragment); + } /* Create NetSurf URL object */ *no_frag = malloc(sizeof(nsurl) + length + 1); /* Add 1 for \0 */ @@ -1770,8 +1771,10 @@ nserror nsurl_defragment(const nsurl *url, nsurl **no_frag) (*no_frag)->length = length; /* Fill out the url string */ - nsurl_get_string(&((*no_frag)->components), (*no_frag)->string, - &str_len, str_flags); + pos = (*no_frag)->string; + memcpy(pos, url->string, length); + pos += length; + *pos = '\0'; /* Give the URL a reference */ (*no_frag)->count = 1; -- cgit v1.2.3