Performance improvements - Avoid using iterators

Change-Id: Iab604aa1ef67acf5d54208a6bc44635632845ae0
main
Ken Wakasa 2012-07-20 17:51:52 +09:00
parent 528738341d
commit afed0567e9
1 changed files with 21 additions and 7 deletions

View File

@ -238,13 +238,17 @@ public class PointerTracker {
} }
public static void setKeyboardActionListener(KeyboardActionListener listener) { public static void setKeyboardActionListener(KeyboardActionListener listener) {
for (final PointerTracker tracker : sTrackers) { final int trackersSize = sTrackers.size();
for (int i = 0; i < trackersSize; ++i) {
final PointerTracker tracker = sTrackers.get(i);
tracker.mListener = listener; tracker.mListener = listener;
} }
} }
public static void setKeyDetector(KeyDetector keyDetector) { public static void setKeyDetector(KeyDetector keyDetector) {
for (final PointerTracker tracker : sTrackers) { final int trackersSize = sTrackers.size();
for (int i = 0; i < trackersSize; ++i) {
final PointerTracker tracker = sTrackers.get(i);
tracker.setKeyDetectorInner(keyDetector); tracker.setKeyDetectorInner(keyDetector);
// Mark that keyboard layout has been changed. // Mark that keyboard layout has been changed.
tracker.mKeyboardLayoutHasBeenChanged = true; tracker.mKeyboardLayoutHasBeenChanged = true;
@ -254,7 +258,9 @@ public class PointerTracker {
} }
public static void dismissAllKeyPreviews() { public static void dismissAllKeyPreviews() {
for (final PointerTracker tracker : sTrackers) { final int trackersSize = sTrackers.size();
for (int i = 0; i < trackersSize; ++i) {
final PointerTracker tracker = sTrackers.get(i);
tracker.getKeyPreviewText().setVisibility(View.INVISIBLE); tracker.getKeyPreviewText().setVisibility(View.INVISIBLE);
tracker.setReleasedKeyGraphics(tracker.mCurrentKey); tracker.setReleasedKeyGraphics(tracker.mCurrentKey);
} }
@ -263,7 +269,9 @@ public class PointerTracker {
// TODO: To handle multi-touch gestures we may want to move this method to // TODO: To handle multi-touch gestures we may want to move this method to
// {@link PointerTrackerQueue}. // {@link PointerTrackerQueue}.
private static InputPointers getIncrementalBatchPoints() { private static InputPointers getIncrementalBatchPoints() {
for (final PointerTracker tracker : sTrackers) { final int trackersSize = sTrackers.size();
for (int i = 0; i < trackersSize; ++i) {
final PointerTracker tracker = sTrackers.get(i);
tracker.mGestureStroke.appendIncrementalBatchPoints(sAggregratedPointers); tracker.mGestureStroke.appendIncrementalBatchPoints(sAggregratedPointers);
} }
return sAggregratedPointers; return sAggregratedPointers;
@ -272,7 +280,9 @@ public class PointerTracker {
// TODO: To handle multi-touch gestures we may want to move this method to // TODO: To handle multi-touch gestures we may want to move this method to
// {@link PointerTrackerQueue}. // {@link PointerTrackerQueue}.
private static InputPointers getAllBatchPoints() { private static InputPointers getAllBatchPoints() {
for (final PointerTracker tracker : sTrackers) { final int trackersSize = sTrackers.size();
for (int i = 0; i < trackersSize; ++i) {
final PointerTracker tracker = sTrackers.get(i);
tracker.mGestureStroke.appendAllBatchPoints(sAggregratedPointers); tracker.mGestureStroke.appendAllBatchPoints(sAggregratedPointers);
} }
return sAggregratedPointers; return sAggregratedPointers;
@ -281,7 +291,9 @@ public class PointerTracker {
// TODO: To handle multi-touch gestures we may want to move this method to // TODO: To handle multi-touch gestures we may want to move this method to
// {@link PointerTrackerQueue}. // {@link PointerTrackerQueue}.
public static void clearBatchInputPointsOfAllPointerTrackers() { public static void clearBatchInputPointsOfAllPointerTrackers() {
for (final PointerTracker tracker : sTrackers) { final int trackersSize = sTrackers.size();
for (int i = 0; i < trackersSize; ++i) {
final PointerTracker tracker = sTrackers.get(i);
tracker.mGestureStroke.reset(); tracker.mGestureStroke.reset();
} }
sAggregratedPointers.reset(); sAggregratedPointers.reset();
@ -290,7 +302,9 @@ public class PointerTracker {
// TODO: To handle multi-touch gestures we may want to move this method to // TODO: To handle multi-touch gestures we may want to move this method to
// {@link PointerTrackerQueue}. // {@link PointerTrackerQueue}.
public static void drawGestureTrailForAllPointerTrackers(Canvas canvas, Paint paint) { public static void drawGestureTrailForAllPointerTrackers(Canvas canvas, Paint paint) {
for (final PointerTracker tracker : sTrackers) { final int trackersSize = sTrackers.size();
for (int i = 0; i < trackersSize; ++i) {
final PointerTracker tracker = sTrackers.get(i);
tracker.mGestureStroke.drawGestureTrail(canvas, paint, tracker.getLastX(), tracker.mGestureStroke.drawGestureTrail(canvas, paint, tracker.getLastX(),
tracker.getLastY()); tracker.getLastY());
} }