New helper to add markers
The add_marker() function is used to create a new marker and add it at the right spot to the relevant marker list. Use it in the add_string_markers() helper (which gets slightly quicker by it). Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>main
parent
7da5d106c7
commit
605dc044c3
52
treesource.c
52
treesource.c
|
@ -139,26 +139,48 @@ static const char *delim_end[] = {
|
|||
[TYPE_STRING] = "",
|
||||
};
|
||||
|
||||
/*
|
||||
* The invariants in the marker list are:
|
||||
* - offsets are non-strictly monotonically increasing
|
||||
* - for a single offset there is at most one type marker
|
||||
* - for a single offset that has both a type marker and non-type markers, the
|
||||
* type marker appears before the others.
|
||||
*/
|
||||
static struct marker **add_marker(struct marker **mi,
|
||||
enum markertype type, unsigned int offset, char *ref)
|
||||
{
|
||||
struct marker *nm;
|
||||
|
||||
while (*mi && (*mi)->offset < offset)
|
||||
mi = &(*mi)->next;
|
||||
|
||||
if (*mi && (*mi)->offset == offset && is_type_marker((*mi)->type)) {
|
||||
if (is_type_marker(type))
|
||||
return mi;
|
||||
mi = &(*mi)->next;
|
||||
}
|
||||
|
||||
if (*mi && (*mi)->offset == offset && type == (*mi)->type)
|
||||
return mi;
|
||||
|
||||
nm = xmalloc(sizeof(*nm));
|
||||
nm->type = type;
|
||||
nm->offset = offset;
|
||||
nm->ref = ref;
|
||||
nm->next = *mi;
|
||||
*mi = nm;
|
||||
|
||||
return &nm->next;
|
||||
}
|
||||
|
||||
static void add_string_markers(struct property *prop)
|
||||
{
|
||||
int l, len = prop->val.len;
|
||||
const char *p = prop->val.val;
|
||||
struct marker **mi = &prop->val.markers;
|
||||
|
||||
for (l = strlen(p) + 1; l < len; l += strlen(p + l) + 1) {
|
||||
struct marker *m, **nextp;
|
||||
|
||||
m = xmalloc(sizeof(*m));
|
||||
m->offset = l;
|
||||
m->type = TYPE_STRING;
|
||||
m->ref = NULL;
|
||||
m->next = NULL;
|
||||
|
||||
/* Find the end of the markerlist */
|
||||
nextp = &prop->val.markers;
|
||||
while (*nextp)
|
||||
nextp = &((*nextp)->next);
|
||||
*nextp = m;
|
||||
}
|
||||
for (l = strlen(p) + 1; l < len; l += strlen(p + l) + 1)
|
||||
mi = add_marker(mi, TYPE_STRING, l, NULL);
|
||||
}
|
||||
|
||||
static enum markertype guess_value_type(struct property *prop)
|
||||
|
|
Loading…
Reference in New Issue