From 9023806b5fa085edfbdb834b965d56d3d1f5c6ff Mon Sep 17 00:00:00 2001 From: Andy2 Date: Tue, 20 Dec 2011 17:24:38 -0800 Subject: [PATCH] cleanup: move instanceof/cast from use of vector elements to addition of elements to save memory and time. --- .../eehouse/android/xw4/DispatchNotify.java | 31 +++++++++---------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DispatchNotify.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DispatchNotify.java index 818ec9a77..b123da272 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DispatchNotify.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DispatchNotify.java @@ -41,7 +41,8 @@ public class DispatchNotify extends Activity { void HandleInvite( final Uri invite ); } - private static HashSet s_running = new HashSet(); + private static HashSet s_running = + new HashSet(); private static HandleRelaysIface s_handler; @Override @@ -95,12 +96,16 @@ public class DispatchNotify extends Activity { public static void SetRunning( Activity running ) { - s_running.add( running ); + if ( running instanceof HandleRelaysIface ) { + s_running.add( (HandleRelaysIface)running ); + } } public static void ClearRunning( Activity running ) { - s_running.remove( running ); + if ( running instanceof HandleRelaysIface ) { + s_running.remove( (HandleRelaysIface)running ); + } } public static void SetRelayIDsHandler( HandleRelaysIface iface ) @@ -116,13 +121,9 @@ public class DispatchNotify extends Activity { s_handler.HandleInvite( data ); handled = true; } else { - for ( Activity activity : s_running ) { - if ( activity instanceof DispatchNotify.HandleRelaysIface ) { - DispatchNotify.HandleRelaysIface iface = - (DispatchNotify.HandleRelaysIface)activity; - iface.HandleInvite( data ); - handled = true; - } + for ( HandleRelaysIface iface : s_running ) { + iface.HandleInvite( data ); + handled = true; } } return handled; @@ -136,13 +137,9 @@ public class DispatchNotify extends Activity { s_handler.HandleRelaysIDs( relayIDs ); handled = true; } else { - for ( Activity activity : s_running ) { - if ( activity instanceof DispatchNotify.HandleRelaysIface ) { - DispatchNotify.HandleRelaysIface iface = - (DispatchNotify.HandleRelaysIface)activity; - iface.HandleRelaysIDs( relayIDs ); - handled = true; - } + for ( HandleRelaysIface iface : s_running ) { + iface.HandleRelaysIDs( relayIDs ); + handled = true; } } return handled;