From c51b14383cea9ab41bc53ae27051a969f6dafef3 Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Sat, 25 Jul 2009 15:47:11 +0000 Subject: Now that libwapcaplet guarantees NUL-termination of strings, stop copying them unnecessarily. svn path=/trunk/netsurf/; revision=8785 --- css/css.c | 15 +-------------- css/internal.c | 15 ++------------- css/select.c | 50 +++++--------------------------------------------- 3 files changed, 8 insertions(+), 72 deletions(-) (limited to 'css') diff --git a/css/css.c b/css/css.c index dbb4f53be..5924ab9db 100644 --- a/css/css.c +++ b/css/css.c @@ -170,7 +170,6 @@ bool nscss_convert(struct content *c, int w, int h) lwc_string *uri; uint64_t media; css_stylesheet *sheet; - char *temp_url; error = css_stylesheet_next_pending_import(c->data.css.sheet, &uri, &media); @@ -185,15 +184,6 @@ bool nscss_convert(struct content *c, int w, int h) break; } - /* Copy URI and ensure it's NUL terminated */ - temp_url = malloc(lwc_string_length(uri) + 1); - if (temp_url == NULL) { - c->status = CONTENT_STATUS_ERROR; - return false; - } - memcpy(temp_url, lwc_string_data(uri), lwc_string_length(uri)); - temp_url[lwc_string_length(uri)] = '\0'; - /* Increase space in table */ imports = realloc(c->data.css.imports, (c->data.css.import_count + 1) * @@ -207,12 +197,11 @@ bool nscss_convert(struct content *c, int w, int h) /* Create content */ i = c->data.css.import_count; c->data.css.imports[c->data.css.import_count++] = - fetchcache(temp_url, + fetchcache(lwc_string_data(uri), nscss_import, (intptr_t) c, i, c->width, c->height, true, NULL, NULL, false, false); if (c->data.css.imports[i] == NULL) { - free(temp_url); c->status = CONTENT_STATUS_ERROR; return false; } @@ -223,8 +212,6 @@ bool nscss_convert(struct content *c, int w, int h) nscss_import, (intptr_t) c, i, c->width, c->height, NULL, NULL, false, c); - free(temp_url); - /* Wait for import to fetch + convert */ while (c->active > 0) { fetch_poll(); diff --git a/css/internal.c b/css/internal.c index fd22af628..b9aa83f0d 100644 --- a/css/internal.c +++ b/css/internal.c @@ -38,26 +38,15 @@ css_error nscss_resolve_url(void *pw, lwc_context *ctx, const char *base, lwc_string *rel, lwc_string **abs) { lwc_error lerror; - char *rel_url, *abs_url, *norm_url; + char *abs_url, *norm_url; url_func_result res; - /* Copy relative URL and ensure it's NUL terminated */ - rel_url = malloc(lwc_string_length(rel) + 1); - if (rel_url == NULL) - return CSS_NOMEM; - - memcpy(rel_url, lwc_string_data(rel), lwc_string_length(rel)); - rel_url[lwc_string_length(rel)] = '\0'; - /* Resolve URI */ - res = url_join(rel_url, base, &abs_url); + res = url_join(lwc_string_data(rel), base, &abs_url); if (res != URL_FUNC_OK) { - free(rel_url); return res == URL_FUNC_NOMEM ? CSS_NOMEM : CSS_INVALID; } - free(rel_url); - /* Normalise it */ res = url_normalize(abs_url, &norm_url); if (res != URL_FUNC_OK) { diff --git a/css/select.c b/css/select.c index 0f2f7327e..38c72ae37 100644 --- a/css/select.c +++ b/css/select.c @@ -745,20 +745,10 @@ css_error node_has_attribute(void *pw, void *node, { xmlNode *n = node; xmlAttr *attr; - char *buf; - - buf = malloc(lwc_string_length(name) + 1); - if (buf == NULL) - return CSS_NOMEM; - - memcpy(buf, lwc_string_data(name), lwc_string_length(name)); - buf[lwc_string_length(name)] = '\0'; - - attr = xmlHasProp(n, (const xmlChar *) buf); + + attr = xmlHasProp(n, (const xmlChar *) lwc_string_data(name)); *match = attr != NULL; - free(buf); - return CSS_OK; } @@ -782,18 +772,10 @@ css_error node_has_attribute_equal(void *pw, void *node, { xmlNode *n = node; xmlChar *attr; - char *buf; - - buf = malloc(lwc_string_length(name) + 1); - if (buf == NULL) - return CSS_NOMEM; - - memcpy(buf, lwc_string_data(name), lwc_string_length(name)); - buf[lwc_string_length(name)] = '\0'; *match = false; - attr = xmlGetProp(n, (const xmlChar *) buf); + attr = xmlGetProp(n, (const xmlChar *) lwc_string_data(name)); if (attr != NULL) { *match = strlen((const char *) attr) == lwc_string_length(value) && @@ -803,8 +785,6 @@ css_error node_has_attribute_equal(void *pw, void *node, xmlFree(attr); } - free(buf); - return CSS_OK; } @@ -828,19 +808,11 @@ css_error node_has_attribute_dashmatch(void *pw, void *node, { xmlNode *n = node; xmlChar *attr; - char *buf; size_t vlen = lwc_string_length(value); - buf = malloc(lwc_string_length(name) + 1); - if (buf == NULL) - return CSS_NOMEM; - - memcpy(buf, lwc_string_data(name), lwc_string_length(name)); - buf[lwc_string_length(name)] = '\0'; - *match = false; - attr = xmlGetProp(n, (const xmlChar *) buf); + attr = xmlGetProp(n, (const xmlChar *) lwc_string_data(name)); if (attr != NULL) { const char *p; const char *start = (const char *) attr; @@ -861,8 +833,6 @@ css_error node_has_attribute_dashmatch(void *pw, void *node, } } - free(buf); - return CSS_OK; } @@ -886,19 +856,11 @@ css_error node_has_attribute_includes(void *pw, void *node, { xmlNode *n = node; xmlChar *attr; - char *buf; size_t vlen = lwc_string_length(value); - buf = malloc(lwc_string_length(name) + 1); - if (buf == NULL) - return CSS_NOMEM; - - memcpy(buf, lwc_string_data(name), lwc_string_length(name)); - buf[lwc_string_length(name)] = '\0'; - *match = false; - attr = xmlGetProp(n, (const xmlChar *) buf); + attr = xmlGetProp(n, (const xmlChar *) lwc_string_data(name)); if (attr != NULL) { const char *p; const char *start = (const char *) attr; @@ -919,8 +881,6 @@ css_error node_has_attribute_includes(void *pw, void *node, } } - free(buf); - return CSS_OK; } -- cgit v1.2.3