Skip to content

Commit 0ffe400

Browse files
No more clone
1 parent f405780 commit 0ffe400

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

firebase-firestore/src/main/java/com/google/firebase/firestore/local/MemoryRemoteDocumentCache.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void add(MutableDocument document, SnapshotVersion readTime) {
5555
hardAssert(
5656
!readTime.equals(SnapshotVersion.NONE),
5757
"Cannot add document to the RemoteDocumentCache with a read time of zero");
58-
docs = docs.insert(document.getKey(), document.clone().withReadTime(readTime));
58+
docs = docs.insert(document.getKey(), document.mutableCopy().withReadTime(readTime));
5959
latestReadTime = readTime.compareTo(latestReadTime) > 0 ? readTime : latestReadTime;
6060

6161
indexManager.addToCollectionParentIndex(document.getKey().getCollectionPath());
@@ -69,7 +69,7 @@ public void remove(DocumentKey key) {
6969
@Override
7070
public MutableDocument get(DocumentKey key) {
7171
Document doc = docs.get(key);
72-
return doc != null ? doc.clone() : MutableDocument.newInvalidDocument(key);
72+
return doc != null ? doc.mutableCopy() : MutableDocument.newInvalidDocument(key);
7373
}
7474

7575
@Override
@@ -117,7 +117,7 @@ public Map<DocumentKey, MutableDocument> getAll(ResourcePath collection, IndexOf
117117
continue;
118118
}
119119

120-
result.put(doc.getKey(), doc.clone());
120+
result.put(doc.getKey(), doc.mutableCopy());
121121
}
122122

123123
return result;

firebase-firestore/src/main/java/com/google/firebase/firestore/model/Document.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
package com.google.firebase.firestore.model;
1616

17-
import androidx.annotation.NonNull;
1817
import androidx.annotation.Nullable;
1918
import com.google.firestore.v1.Value;
2019
import java.util.Comparator;
@@ -23,7 +22,7 @@
2322
* Represents a document in Firestore with a key, version, data and whether the data has local
2423
* mutations applied to it.
2524
*/
26-
public interface Document extends Cloneable {
25+
public interface Document {
2726
/** A document comparator that returns document by key and key only. */
2827
Comparator<Document> KEY_COMPARATOR = (left, right) -> left.getKey().compareTo(right.getKey());
2928

@@ -75,6 +74,6 @@ public interface Document extends Cloneable {
7574
*/
7675
boolean hasPendingWrites();
7776

78-
@NonNull
79-
MutableDocument clone();
77+
/** Creates a mutable copy of this document. */
78+
MutableDocument mutableCopy();
8079
}

firebase-firestore/src/main/java/com/google/firebase/firestore/model/MutableDocument.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ public boolean isUnknownDocument() {
229229

230230
@Override
231231
@NonNull
232-
public MutableDocument clone() {
232+
public MutableDocument mutableCopy() {
233233
return new MutableDocument(key, documentType, version, readTime, value.clone(), documentState);
234234
}
235235

0 commit comments

Comments
 (0)