We were already assuming that the sampled-out listeners are a subset of sampled listeners, so optimize state update.

This commit is contained in:
Rodrigo Damazio
2011-05-04 22:44:36 -03:00
parent 8a23af8581
commit 1254df2db1
@@ -934,29 +934,15 @@ public class TrackDataHub {
// Always keep the sampling frequency - if it changes we'll do a full reload above anyway. // Always keep the sampling frequency - if it changes we'll do a full reload above anyway.
lastSamplingFrequency = pointSamplingFrequency; lastSamplingFrequency = pointSamplingFrequency;
// Update the listener state
// TODO: Optimize this (sampledOutListeners should be a subset of sampledListeners, plus
// getRegistration does a lookup for every listener, and this is in the critical path).
updateListenersState(sampledListeners,
currentSelectedTrackId, localLastSeenLocationId, pointSamplingFrequency);
updateListenersState(sampledOutListeners,
currentSelectedTrackId, localLastSeenLocationId, pointSamplingFrequency);
for (TrackDataListener listener : sampledListeners) { for (TrackDataListener listener : sampledListeners) {
listener.onNewTrackPointsDone(); listener.onNewTrackPointsDone();
}
}
private void updateListenersState(Set<TrackDataListener> sampledListeners, // Update the listener state
long trackId, long lastPointId, int samplingFrequency) { ListenerRegistration registration = listeners.getRegistration(listener);
synchronized (listeners) { if (registration != null) {
for (TrackDataListener listener : sampledListeners) { registration.lastTrackId = currentSelectedTrackId;
ListenerRegistration registration = listeners.getRegistration(listener); registration.lastPointId = localLastSeenLocationId;
if (registration != null) { registration.lastSamplingFrequency = pointSamplingFrequency;
registration.lastTrackId = trackId;
registration.lastPointId = lastPointId;
registration.lastSamplingFrequency = samplingFrequency;
}
} }
} }
} }