Skip to content

Commit 206b32e

Browse files
committed
xml/export: factorize info attr export
Signed-off-by: Brice Goglin <[email protected]>
1 parent 2fc7c23 commit 206b32e

File tree

1 file changed

+25
-24
lines changed

1 file changed

+25
-24
lines changed

hwloc/topology-xml.c

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1970,6 +1970,27 @@ hwloc__xml_export_safestrdup(const char *old)
19701970
return new;
19711971
}
19721972

1973+
static void
1974+
hwloc__xml_export_info_attr_safe(hwloc__xml_export_state_t state, const char *name, const char *value)
1975+
{
1976+
struct hwloc__xml_export_state_s childstate;
1977+
state->new_child(state, &childstate, "info");
1978+
childstate.new_prop(&childstate, "name", name);
1979+
childstate.new_prop(&childstate, "value", value);
1980+
childstate.end_object(&childstate, "info");
1981+
}
1982+
1983+
static void
1984+
hwloc__xml_export_info_attr(hwloc__xml_export_state_t state, const char *_name, const char *_value)
1985+
{
1986+
char *name = hwloc__xml_export_safestrdup(_name);
1987+
char *value = hwloc__xml_export_safestrdup(_value);
1988+
if (name && value)
1989+
hwloc__xml_export_info_attr_safe(state, name, value);
1990+
free(name);
1991+
free(value);
1992+
}
1993+
19731994
static void
19741995
hwloc__xml_export_object_contents (hwloc__xml_export_state_t state, hwloc_topology_t topology, hwloc_obj_t obj, unsigned long flags)
19751996
{
@@ -2123,19 +2144,8 @@ hwloc__xml_export_object_contents (hwloc__xml_export_state_t state, hwloc_topolo
21232144
break;
21242145
}
21252146

2126-
for(i=0; i<obj->infos_count; i++) {
2127-
char *name = hwloc__xml_export_safestrdup(obj->infos[i].name);
2128-
char *value = hwloc__xml_export_safestrdup(obj->infos[i].value);
2129-
if (name && value) {
2130-
struct hwloc__xml_export_state_s childstate;
2131-
state->new_child(state, &childstate, "info");
2132-
childstate.new_prop(&childstate, "name", name);
2133-
childstate.new_prop(&childstate, "value", value);
2134-
childstate.end_object(&childstate, "info");
2135-
}
2136-
free(name);
2137-
free(value);
2138-
}
2147+
for(i=0; i<obj->infos_count; i++)
2148+
hwloc__xml_export_info_attr(state, obj->infos[i].name, obj->infos[i].value);
21392149
if (obj->userdata && topology->userdata_export_cb)
21402150
topology->userdata_export_cb((void*) state, topology, obj);
21412151
}
@@ -2428,17 +2438,8 @@ hwloc__xml_export_cpukinds(hwloc__xml_export_state_t state, hwloc_topology_t top
24282438
cstate.new_prop(&cstate, "forced_efficiency", tmp);
24292439
}
24302440

2431-
for(j=0; j<kind->nr_infos; j++) {
2432-
char *name = hwloc__xml_export_safestrdup(kind->infos[j].name);
2433-
char *value = hwloc__xml_export_safestrdup(kind->infos[j].value);
2434-
struct hwloc__xml_export_state_s istate;
2435-
cstate.new_child(&cstate, &istate, "info");
2436-
istate.new_prop(&istate, "name", name);
2437-
istate.new_prop(&istate, "value", value);
2438-
istate.end_object(&istate, "info");
2439-
free(name);
2440-
free(value);
2441-
}
2441+
for(j=0; j<kind->nr_infos; j++)
2442+
hwloc__xml_export_info_attr(&cstate, kind->infos[j].name, kind->infos[j].value);
24422443

24432444
cstate.end_object(&cstate, "cpukind");
24442445
}

0 commit comments

Comments
 (0)