From 1254df2db116c197f25439add32ff0a1354f2a69 Mon Sep 17 00:00:00 2001 From: Rodrigo Damazio Date: Wed, 4 May 2011 22:44:36 -0300 Subject: [PATCH] We were already assuming that the sampled-out listeners are a subset of sampled listeners, so optimize state update. --- .../apps/mytracks/content/TrackDataHub.java | 26 +++++-------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/MyTracks/src/com/google/android/apps/mytracks/content/TrackDataHub.java b/MyTracks/src/com/google/android/apps/mytracks/content/TrackDataHub.java index f8205a35a..9b8467414 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/content/TrackDataHub.java +++ b/MyTracks/src/com/google/android/apps/mytracks/content/TrackDataHub.java @@ -934,29 +934,15 @@ public class TrackDataHub { // Always keep the sampling frequency - if it changes we'll do a full reload above anyway. 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) { listener.onNewTrackPointsDone(); - } - } - private void updateListenersState(Set sampledListeners, - long trackId, long lastPointId, int samplingFrequency) { - synchronized (listeners) { - for (TrackDataListener listener : sampledListeners) { - ListenerRegistration registration = listeners.getRegistration(listener); - if (registration != null) { - registration.lastTrackId = trackId; - registration.lastPointId = lastPointId; - registration.lastSamplingFrequency = samplingFrequency; - } + // Update the listener state + ListenerRegistration registration = listeners.getRegistration(listener); + if (registration != null) { + registration.lastTrackId = currentSelectedTrackId; + registration.lastPointId = localLastSeenLocationId; + registration.lastSamplingFrequency = pointSamplingFrequency; } } }