Skip to content

Commit b98e38d

Browse files
authored
refactor: Optimize arraylist instanciation. (#1502)
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly: - [ ] Make sure to open an issue as a [bug/issue](https://togithub.com/googleapis/java-firestore/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [ ] Ensure the tests and linter pass - [ ] Code coverage does not decrease (if any source code was changed) - [ ] Appropriate docs were updated (if necessary) Fixes #<issue_number_goes_here> ☕️ If you write sample code, please follow the [samples format]( https://togithub.com/GoogleCloudPlatform/java-docs-samples/blob/main/SAMPLE_FORMAT.md).
1 parent ef43b1b commit b98e38d

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

google-cloud-firestore/src/main/java/com/google/cloud/firestore/QuerySnapshot.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,9 @@ public Iterator<QueryDocumentSnapshot> iterator() {
206206
*/
207207
@Nonnull
208208
public <T> List<T> toObjects(@Nonnull Class<T> clazz) {
209-
List<T> results = new ArrayList<>();
210-
211-
for (DocumentSnapshot documentSnapshot : getDocuments()) {
209+
List<QueryDocumentSnapshot> documents = getDocuments();
210+
List<T> results = new ArrayList<>(documents.size());
211+
for (DocumentSnapshot documentSnapshot : documents) {
212212
results.add(
213213
CustomClassMapper.convertToCustomClass(
214214
documentSnapshot.getData(), clazz, documentSnapshot.getReference()));

0 commit comments

Comments
 (0)