Merge "Reduce memory allocations and improve sorting in DocumentsUI by 8.42%." into nyc-dev

This commit is contained in:
Tomasz Mikolajewski
2016-03-18 02:25:07 +00:00
committed by Android (Google) Code Review
3 changed files with 10 additions and 16 deletions

View File

@@ -22,6 +22,7 @@ import static com.android.documentsui.State.SORT_ORDER_LAST_MODIFIED;
import static com.android.documentsui.State.SORT_ORDER_SIZE; import static com.android.documentsui.State.SORT_ORDER_SIZE;
import android.database.Cursor; import android.database.Cursor;
import android.database.MergeCursor;
import android.os.Bundle; import android.os.Bundle;
import android.provider.DocumentsContract; import android.provider.DocumentsContract;
import android.provider.DocumentsContract.Document; import android.provider.DocumentsContract.Document;
@@ -72,16 +73,6 @@ public class Model {
@Nullable String error; @Nullable String error;
@Nullable DocumentInfo doc; @Nullable DocumentInfo doc;
/**
* Generates a Model ID for a cursor entry that refers to a document. The Model ID is a unique
* string that can be used to identify the document referred to by the cursor.
*
* @param c A cursor that refers to a document.
*/
static String createModelId(String authority, String docId) {
return authority + "|" + docId;
}
private void notifyUpdateListeners() { private void notifyUpdateListeners() {
for (UpdateListener listener: mUpdateListeners) { for (UpdateListener listener: mUpdateListeners) {
listener.onModelUpdate(this); listener.onModelUpdate(this);
@@ -176,8 +167,13 @@ public class Model {
// Generates a Model ID for a cursor entry that refers to a document. The Model ID is a // Generates a Model ID for a cursor entry that refers to a document. The Model ID is a
// unique string that can be used to identify the document referred to by the cursor. // unique string that can be used to identify the document referred to by the cursor.
mIds[pos] = createModelId( // If the cursor is a merged cursor over multiple authorities, then prefix the ids
getStringOrEmpty(mAuthorityIndex), getStringOrEmpty(mDocIdIndex)); // with the authority to avoid collisions.
if (mCursor instanceof MergeCursor) {
mIds[pos] = getStringOrEmpty(mAuthorityIndex) + "|" + getStringOrEmpty(mDocIdIndex);
} else {
mIds[pos] = getStringOrEmpty(mDocIdIndex);
}
mimeType = getStringOrEmpty(mMimeTypeIndex); mimeType = getStringOrEmpty(mMimeTypeIndex);
isDirs[pos] = Document.MIME_TYPE_DIR.equals(mimeType); isDirs[pos] = Document.MIME_TYPE_DIR.equals(mimeType);

View File

@@ -284,7 +284,7 @@ public class ModelTest extends AndroidTestCase {
String id = Integer.toString(i); String id = Integer.toString(i);
row.add(RootCursorWrapper.COLUMN_AUTHORITY, AUTHORITY); row.add(RootCursorWrapper.COLUMN_AUTHORITY, AUTHORITY);
row.add(Document.COLUMN_DOCUMENT_ID, id); row.add(Document.COLUMN_DOCUMENT_ID, id);
currentDownloads.add(Model.createModelId(AUTHORITY, id)); currentDownloads.add(id);
} }
DirectoryResult r = new DirectoryResult(); DirectoryResult r = new DirectoryResult();

View File

@@ -62,9 +62,7 @@ public class TestModel extends Model {
update(r); update(r);
} }
// Note that model id includes authority qualifier and is distinct
// WRT documentId because of this.
String idForPosition(int p) { String idForPosition(int p) {
return createModelId(mAuthority, Integer.toString(p)); return Integer.toString(p);
} }
} }