まあ、パフォーマンスのヒントには次のように記載されています。
したがって、デフォルトで強化された for ループを使用する必要がありますが、パフォーマンスが重要な ArrayList の繰り返しには手書きのカウント ループを検討してください。
しかし、ioshed 2013アプリケーションを見ると、ほとんどの開発者にとって例と見なされます。ScheduleUpdaterService.java
特に、次のことがわかります。
void processPendingScheduleUpdates() {
try {
// Operate on a local copy of the schedule update list so as not to block
// the main thread adding to this list
List<Intent> scheduleUpdates = new ArrayList<Intent>();
synchronized (mScheduleUpdates) {
scheduleUpdates.addAll(mScheduleUpdates);
mScheduleUpdates.clear();
}
SyncHelper syncHelper = new SyncHelper(this);
for (Intent updateIntent : scheduleUpdates) {
String sessionId = updateIntent.getStringExtra(EXTRA_SESSION_ID);
boolean inSchedule = updateIntent.getBooleanExtra(EXTRA_IN_SCHEDULE, false);
LOGI(TAG, "addOrRemoveSessionFromSchedule:"
+ " sessionId=" + sessionId
+ " inSchedule=" + inSchedule);
syncHelper.addOrRemoveSessionFromSchedule(this, sessionId, inSchedule);
}
} catch (IOException e) {
// TODO: do something useful here, like revert the changes locally in the
// content provider to maintain client/server sync
LOGE(TAG, "Error processing schedule update", e);
}
}
を介した for ループの反復が拡張されていることに注意してください。scheduleUpdates
ただし、このようなタイプの for の反復を避けることをお勧めしますArrayList
。
それは、アプリケーションのこの部分がパフォーマンスの観点から重要であるとは見なされていないためですか、それとも私が何かを理解していないのでしょうか? どうもありがとう。