mirror of
https://github.com/moparisthebest/k-9
synced 2025-01-31 15:20:09 -05:00
Perf improvement: use parcels instead of serializable
Standard Java serialization is slow on Android. Replacing it w/ parcelable makes it around 10x faster (on a N1, with ~ 500 messages in the list). To avoid further confusion and potential bugs MessageReference was made no longer implement Serializable.
This commit is contained in:
parent
68381d4725
commit
685df0ff67
@ -70,7 +70,7 @@ public class ChooseFolder extends K9ListActivity {
|
||||
Intent intent = getIntent();
|
||||
String accountUuid = intent.getStringExtra(EXTRA_ACCOUNT);
|
||||
mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
|
||||
mMessageReference = (MessageReference)intent.getSerializableExtra(EXTRA_MESSAGE);
|
||||
mMessageReference = intent.getParcelableExtra(EXTRA_MESSAGE);
|
||||
mFolder = intent.getStringExtra(EXTRA_CUR_FOLDER);
|
||||
mSelectFolder = intent.getStringExtra(EXTRA_SEL_FOLDER);
|
||||
if (intent.getStringExtra(EXTRA_SHOW_CURRENT) != null) {
|
||||
|
@ -327,7 +327,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
|
||||
|
||||
final Intent intent = getIntent();
|
||||
|
||||
mMessageReference = (MessageReference) intent.getSerializableExtra(EXTRA_MESSAGE_REFERENCE);
|
||||
mMessageReference = intent.getParcelableExtra(EXTRA_MESSAGE_REFERENCE);
|
||||
mSourceMessageBody = intent.getStringExtra(EXTRA_MESSAGE_BODY);
|
||||
|
||||
if (K9.DEBUG && mSourceMessageBody != null)
|
||||
|
@ -1164,7 +1164,7 @@ public class MessageList
|
||||
return;
|
||||
|
||||
final String destFolderName = data.getStringExtra(ChooseFolder.EXTRA_NEW_FOLDER);
|
||||
final MessageReference ref = (MessageReference)data.getSerializableExtra(ChooseFolder.EXTRA_MESSAGE);
|
||||
final MessageReference ref = data.getParcelableExtra(ChooseFolder.EXTRA_MESSAGE);
|
||||
final MessageInfoHolder m = mAdapter.getMessage(ref);
|
||||
|
||||
if ((destFolderName != null) && (m != null)) {
|
||||
|
@ -1,16 +1,16 @@
|
||||
package com.fsck.k9.activity;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.util.Log;
|
||||
import com.fsck.k9.K9;
|
||||
import com.fsck.k9.helper.Utility;
|
||||
import com.fsck.k9.mail.Flag;
|
||||
import com.fsck.k9.mail.MessagingException;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
public class MessageReference implements Serializable {
|
||||
private static final long serialVersionUID = -1625198750239083389L;
|
||||
public class MessageReference implements Parcelable {
|
||||
public String accountUuid;
|
||||
public String folderName;
|
||||
public String uid;
|
||||
@ -121,4 +121,35 @@ public class MessageReference implements Serializable {
|
||||
", flag=" + flag +
|
||||
'}';
|
||||
}
|
||||
|
||||
public static final Creator<MessageReference> CREATOR = new Creator<MessageReference>() {
|
||||
@Override
|
||||
public MessageReference createFromParcel(Parcel source) {
|
||||
MessageReference ref = new MessageReference();
|
||||
ref.uid = source.readString();
|
||||
ref.accountUuid = source.readString();
|
||||
ref.folderName = source.readString();
|
||||
String flag = source.readString();
|
||||
if (flag != null) ref.flag = Flag.valueOf(flag);
|
||||
return ref;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MessageReference[] newArray(int size) {
|
||||
return new MessageReference[size];
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeString(uid);
|
||||
dest.writeString(accountUuid);
|
||||
dest.writeString(folderName);
|
||||
dest.writeString(flag == null ? null : flag.name());
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import android.content.res.Configuration;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Parcelable;
|
||||
import android.util.Config;
|
||||
import android.util.Log;
|
||||
import android.view.*;
|
||||
@ -26,7 +27,6 @@ import com.fsck.k9.view.AttachmentView;
|
||||
import com.fsck.k9.view.ToggleScrollView;
|
||||
import com.fsck.k9.view.SingleMessageView;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
|
||||
public class MessageView extends K9Activity implements OnClickListener {
|
||||
@ -269,14 +269,14 @@ public class MessageView extends K9Activity implements OnClickListener {
|
||||
}
|
||||
|
||||
|
||||
public static void actionView(Context context, MessageReference messRef, List<MessageReference> messReferences) {
|
||||
public static void actionView(Context context, MessageReference messRef, ArrayList<MessageReference> messReferences) {
|
||||
actionView(context, messRef, messReferences, null);
|
||||
}
|
||||
|
||||
public static void actionView(Context context, MessageReference messRef, List<MessageReference> messReferences, Bundle extras) {
|
||||
public static void actionView(Context context, MessageReference messRef, ArrayList<MessageReference> messReferences, Bundle extras) {
|
||||
Intent i = new Intent(context, MessageView.class);
|
||||
i.putExtra(EXTRA_MESSAGE_REFERENCE, messRef);
|
||||
i.putExtra(EXTRA_MESSAGE_REFERENCES, (Serializable) messReferences);
|
||||
i.putParcelableArrayListExtra(EXTRA_MESSAGE_REFERENCES, messReferences);
|
||||
if (extras != null) {
|
||||
i.putExtras(extras);
|
||||
}
|
||||
@ -349,16 +349,14 @@ public class MessageView extends K9Activity implements OnClickListener {
|
||||
displayMessage(mMessageReference);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void restoreMessageReferences(Bundle icicle) {
|
||||
mMessageReference = (MessageReference) icicle.getSerializable(EXTRA_MESSAGE_REFERENCE);
|
||||
mMessageReferences = (ArrayList<MessageReference>) icicle.getSerializable(EXTRA_MESSAGE_REFERENCES);
|
||||
mMessageReference = icicle.getParcelable(EXTRA_MESSAGE_REFERENCE);
|
||||
mMessageReferences = icicle.getParcelableArrayList(EXTRA_MESSAGE_REFERENCES);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void restoreMessageReferencesExtra(Intent intent) {
|
||||
mMessageReference = (MessageReference) intent.getSerializableExtra(EXTRA_MESSAGE_REFERENCE);
|
||||
mMessageReferences = (ArrayList<MessageReference>) intent.getSerializableExtra(EXTRA_MESSAGE_REFERENCES);
|
||||
mMessageReference = intent.getParcelableExtra(EXTRA_MESSAGE_REFERENCE);
|
||||
mMessageReferences = intent.getParcelableArrayListExtra(EXTRA_MESSAGE_REFERENCES);
|
||||
}
|
||||
|
||||
private void setupButtonViews() {
|
||||
@ -418,8 +416,8 @@ public class MessageView extends K9Activity implements OnClickListener {
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
outState.putSerializable(EXTRA_MESSAGE_REFERENCE, mMessageReference);
|
||||
outState.putSerializable(EXTRA_MESSAGE_REFERENCES, mMessageReferences);
|
||||
outState.putParcelable(EXTRA_MESSAGE_REFERENCE, mMessageReference);
|
||||
outState.putParcelableArrayList(EXTRA_MESSAGE_REFERENCES, mMessageReferences);
|
||||
outState.putSerializable(STATE_PGP_DATA, mPgpData);
|
||||
outState.putBoolean(SHOW_PICTURES, mMessageView.showPictures());
|
||||
}
|
||||
@ -743,7 +741,7 @@ public class MessageView extends K9Activity implements OnClickListener {
|
||||
return;
|
||||
String destFolderName = data.getStringExtra(ChooseFolder.EXTRA_NEW_FOLDER);
|
||||
String srcFolderName = data.getStringExtra(ChooseFolder.EXTRA_CUR_FOLDER);
|
||||
MessageReference ref = (MessageReference) data.getSerializableExtra(ChooseFolder.EXTRA_MESSAGE);
|
||||
MessageReference ref = data.getParcelableExtra(ChooseFolder.EXTRA_MESSAGE);
|
||||
if (mMessageReference.equals(ref)) {
|
||||
mAccount.setLastSelectedFolderName(destFolderName);
|
||||
switch (requestCode) {
|
||||
|
Loading…
Reference in New Issue
Block a user