On Thu, Aug 11, 2016 at 06:11:29PM +0200, Lluís Vilanova wrote: > An explicit if/else is clearer than arithmetic assuming #true is 1, > while the compiler should be able to generate just as optimal code. > > Signed-off-by: Lluís Vilanova <vilan...@ac.upc.edu> > --- > stubs/trace-control.c | 9 +++++++-- > trace/control-target.c | 18 ++++++++++++++---- > 2 files changed, 21 insertions(+), 6 deletions(-) > > diff --git a/stubs/trace-control.c b/stubs/trace-control.c > index 3740c38..099c2b5 100644 > --- a/stubs/trace-control.c > +++ b/stubs/trace-control.c > @@ -21,8 +21,13 @@ void trace_event_set_state_dynamic(TraceEvent *ev, bool > state) > TraceEventID id; > assert(trace_event_get_state_static(ev)); > id = trace_event_get_id(ev); > - trace_events_enabled_count += state - trace_events_dstate[id]; > - trace_events_dstate[id] = state; > + if (state) { > + trace_events_enabled_count++; > + trace_events_dstate[id] = 1; > + } else { > + trace_events_enabled_count--;
SHouldn't this be trace_events_enabled_count -= trace_events_dstate[id]; as it is possible to call this method for a trace event that is a per-vcpu event > + trace_events_dstate[id] = 0; > + } > } > > void trace_event_set_vcpu_state_dynamic(CPUState *vcpu, > diff --git a/trace/control-target.c b/trace/control-target.c > index 4ee3733..4e2e727 100644 > --- a/trace/control-target.c > +++ b/trace/control-target.c > @@ -18,8 +18,13 @@ void trace_event_set_state_dynamic_init(TraceEvent *ev, > bool state) > TraceEventID id = trace_event_get_id(ev); > assert(trace_event_get_state_static(ev)); > /* Ignore "vcpu" property, since no vCPUs have been created yet */ > - trace_events_enabled_count += state - trace_events_dstate[id]; > - trace_events_dstate[id] = state; > + if (state) { > + trace_events_enabled_count++; > + trace_events_dstate[id] = 1; > + } else { > + trace_events_enabled_count--; > + trace_events_dstate[id] = 0; > + } > } > > void trace_event_set_state_dynamic(TraceEvent *ev, bool state) > @@ -32,8 +37,13 @@ void trace_event_set_state_dynamic(TraceEvent *ev, bool > state) > } > } else { > TraceEventID id = trace_event_get_id(ev); > - trace_events_enabled_count += state - trace_events_dstate[id]; > - trace_events_dstate[id] = state; > + if (state) { > + trace_events_enabled_count++; > + trace_events_dstate[id] = 1; > + } else { > + trace_events_enabled_count--; > + trace_events_dstate[id] = 0; > + } > } > } > > Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|