Now that libwapcaplet guarantees NUL-termination of strings, stop copying them unnecessarily.

svn path=/trunk/netsurf/; revision=8785
This commit is contained in:
John Mark Bell 2009-07-25 15:47:11 +00:00
parent 2c00c55963
commit c51b14383c
4 changed files with 12 additions and 116 deletions

View File

@ -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();

View File

@ -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) {

View File

@ -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;
}

View File

@ -130,10 +130,6 @@ static bool box_get_attribute(xmlNode *n, const char *attribute,
void *context, char **value);
static struct frame_dimension *box_parse_multi_lengths(const char *s,
unsigned int *count);
static bool fetch_object_interned_url(struct content *c, lwc_string *url,
struct box *box, const content_type *permitted_types,
int available_width, int available_height,
bool background);
/* element_table must be sorted by name */
struct element_entry {
@ -519,8 +515,8 @@ bool box_construct_element(xmlNode *n, struct content *content,
if (css_computed_list_style_image(style, &image_uri) ==
CSS_LIST_STYLE_IMAGE_URI &&
image_uri != NULL) {
if (!fetch_object_interned_url(content,
image_uri,
if (!html_fetch_object(content,
lwc_string_data(image_uri),
marker,
0, content->available_width,
1000, false))
@ -582,8 +578,8 @@ bool box_construct_element(xmlNode *n, struct content *content,
if (css_computed_background_image(style, &bgimage_uri) ==
CSS_BACKGROUND_IMAGE_IMAGE &&
bgimage_uri != NULL) {
if (!fetch_object_interned_url(content,
bgimage_uri,
if (!html_fetch_object(content,
lwc_string_data(bgimage_uri),
box, image_types, content->available_width,
1000, true))
return false;
@ -2358,39 +2354,3 @@ struct frame_dimension *box_parse_multi_lengths(const char *s,
return length;
}
/**
* Fetch an object from an interned URL
*
* \param c Current content
* \param url URL to fetch
* \param box Box containing object
* \param permitted_types Array of permitted types terminated by
* CONTENT_UNKNOWN, or NULL for all types
* \param available_width Estimate of width of object
* \param available_height Estimate of height of object
* \param background This object forms the box background
* \return true on success, false on memory exhaustion
*/
bool fetch_object_interned_url(struct content *c, lwc_string *url,
struct box *box, const content_type *permitted_types,
int available_width, int available_height,
bool background)
{
char *url_buf;
bool ret = true;
url_buf = malloc(lwc_string_length(url) + 1);
if (url_buf == NULL)
return false;
memcpy(url_buf, lwc_string_data(url), lwc_string_length(url));
url_buf[lwc_string_length(url)] = '\0';
ret = html_fetch_object(c, url_buf, box, permitted_types,
available_width, available_height, background);
free(url_buf);
return ret;
}