Skip to content

Commit ad35e99

Browse files
authored
Merge pull request #13 from ItzNotABug/misc-updates
Misc updates
2 parents eed80c7 + 9769739 commit ad35e99

2 files changed

Lines changed: 19 additions & 5 deletions

File tree

dfc/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ android {
2222
}
2323

2424
compileOptions {
25-
sourceCompatibility JavaVersion.VERSION_1_8
26-
targetCompatibility JavaVersion.VERSION_1_8
25+
sourceCompatibility JavaVersion.VERSION_17
26+
targetCompatibility JavaVersion.VERSION_17
2727
}
2828

2929
kotlinOptions {
30-
jvmTarget = '1.8'
30+
jvmTarget = JavaVersion.VERSION_17.toString()
3131
}
3232
}

dfc/src/main/java/com/lazygeniouz/dfc/resolver/ResolverCompat.kt

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,11 @@ internal object ResolverCompat {
8181
*/
8282
internal fun count(context: Context, uri: Uri): Int {
8383
val childrenUri = createChildrenUri(uri)
84-
getCursor(context, childrenUri, iconProjection)?.use { cursor -> return cursor.count }
85-
return 0
84+
return getCursor(
85+
context,
86+
childrenUri,
87+
iconProjection
88+
)?.use { cursor -> return cursor.count } ?: 0
8689
}
8790

8891
/**
@@ -108,6 +111,17 @@ internal object ResolverCompat {
108111
val listOfDocuments = arrayListOf<DocumentFileCompat>()
109112

110113
getCursor(context, childrenUri, fullProjection)?.use { cursor ->
114+
val itemCount = cursor.count
115+
/**
116+
* Pre-sizing the list to avoid resizing overhead.
117+
* This is especially beneficial for directories with a large number of files.
118+
*
119+
* Memory comparison for 8192 files:
120+
* 1. With pre-sizing: 3.10 MB
121+
* 2. Without pre-sizing: 9.60 MB
122+
*/
123+
if (itemCount > 10) listOfDocuments.ensureCapacity(itemCount)
124+
111125
while (cursor.moveToNext()) {
112126
val documentId: String = cursor.getString(0)
113127
val documentUri = DocumentsContract.buildDocumentUriUsingTree(uri, documentId)

0 commit comments

Comments
 (0)