21
21
import java .util .Date ;
22
22
import java .util .HashMap ;
23
23
import java .util .HashSet ;
24
- import java .util .IdentityHashMap ;
25
24
import java .util .Iterator ;
26
25
import java .util .LinkedList ;
27
26
import java .util .List ;
@@ -306,7 +305,6 @@ public String toString() {
306
305
307
306
// Cached State
308
307
private final Map <String , Object > estimatedData ;
309
- private final Map <Object , ParseJSONCacheItem > hashedObjects ; // For mutable containers
310
308
311
309
private String localId ;
312
310
private final ParseMulticastDelegate <ParseObject > saveEvent = new ParseMulticastDelegate <>();
@@ -383,7 +381,6 @@ public ParseObject(String theClassName) {
383
381
operationSetQueue = new LinkedList <>();
384
382
operationSetQueue .add (new ParseOperationSet ());
385
383
estimatedData = new HashMap <>();
386
- hashedObjects = new IdentityHashMap <>();
387
384
388
385
State .Init <?> builder = newStateBuilder (theClassName );
389
386
// When called from new, assume hasData for the whole object is true.
@@ -615,16 +612,6 @@ public Void then(Task<Void> task) throws Exception {
615
612
}
616
613
}
617
614
618
- private void addToHashedObjects (Object object ) {
619
- synchronized (mutex ) {
620
- try {
621
- hashedObjects .put (object , new ParseJSONCacheItem (object ));
622
- } catch (JSONException e ) {
623
- throw new IllegalArgumentException ("Couldn't serialize container value to JSON." );
624
- }
625
- }
626
- }
627
-
628
615
/**
629
616
* Converts a {@code ParseObject.State} to a {@code ParseObject}.
630
617
*
@@ -752,7 +739,6 @@ private void setState(State newState, boolean notifyIfObjectIdChanges) {
752
739
}
753
740
754
741
rebuildEstimatedData ();
755
- checkpointAllMutableContainers ();
756
742
}
757
743
}
758
744
@@ -847,7 +833,6 @@ public void revert(String key) {
847
833
if (isDirty (key )) {
848
834
currentOperations ().remove (key );
849
835
rebuildEstimatedData ();
850
- checkpointAllMutableContainers ();
851
836
}
852
837
}
853
838
}
@@ -861,7 +846,6 @@ public void revert() {
861
846
if (isDirty ()) {
862
847
currentOperations ().clear ();
863
848
rebuildEstimatedData ();
864
- checkpointAllMutableContainers ();
865
849
}
866
850
}
867
851
}
@@ -1036,8 +1020,6 @@ protected boolean visit(Object object) {
1036
1020
1037
1021
/* package */ JSONObject toRest (
1038
1022
State state , List <ParseOperationSet > operationSetQueue , ParseEncoder objectEncoder ) {
1039
- checkForChangesToMutableContainers ();
1040
-
1041
1023
// Public data goes in dataJSON; special fields go in objectJSON.
1042
1024
JSONObject json = new JSONObject ();
1043
1025
@@ -1187,7 +1169,6 @@ public boolean isDirty() {
1187
1169
1188
1170
/* package */ boolean isDirty (boolean considerChildren ) {
1189
1171
synchronized (mutex ) {
1190
- checkForChangesToMutableContainers ();
1191
1172
return (isDeleted || getObjectId () == null || hasChanges () || (considerChildren && hasDirtyChildren ()));
1192
1173
}
1193
1174
}
@@ -1222,80 +1203,6 @@ public boolean isDirty(String key) {
1222
1203
}
1223
1204
}
1224
1205
1225
- //region Mutable Containers
1226
-
1227
- /* package */ boolean isContainerObject (String key , Object object ) {
1228
- return (object instanceof JSONObject || object instanceof JSONArray
1229
- || object instanceof Map || object instanceof List
1230
- || object instanceof ParseACL || object instanceof ParseGeoPoint );
1231
- }
1232
-
1233
- /**
1234
- * Updates the JSON cache value for all of the values in estimatedData.
1235
- */
1236
- private void checkpointAllMutableContainers () {
1237
- synchronized (mutex ) {
1238
- for (Map .Entry <String , Object > entry : estimatedData .entrySet ()) {
1239
- checkpointMutableContainer (entry .getKey (), entry .getValue ());
1240
- }
1241
- }
1242
- }
1243
-
1244
- /**
1245
- * Updates the JSON cache value for the given object.
1246
- */
1247
- private void checkpointMutableContainer (String key , Object object ) {
1248
- synchronized (mutex ) {
1249
- if (isContainerObject (key , object )) {
1250
- addToHashedObjects (object );
1251
- }
1252
- }
1253
- }
1254
-
1255
- /**
1256
- * Inspects to see if a given mutable container owned by this object has been mutated, and treats
1257
- * any mutation as a new {@link #put(String, Object)} call.
1258
- */
1259
- private void checkForChangesToMutableContainer (String key , Object object ) {
1260
- synchronized (mutex ) {
1261
- if (isContainerObject (key , object )) {
1262
- ParseJSONCacheItem oldCacheItem = hashedObjects .get (object );
1263
- if (oldCacheItem == null ) {
1264
- throw new IllegalArgumentException (
1265
- "ParseObject contains container item that isn't cached." );
1266
- } else {
1267
- ParseJSONCacheItem newCacheItem ;
1268
- try {
1269
- newCacheItem = new ParseJSONCacheItem (object );
1270
- } catch (JSONException e ) {
1271
- throw new RuntimeException (e );
1272
- }
1273
- if (!oldCacheItem .equals (newCacheItem )) {
1274
- // A mutable container changed out from under us. Treat it as a set operation.
1275
- performOperation (key , new ParseSetOperation (object ));
1276
- }
1277
- }
1278
- } else {
1279
- hashedObjects .remove (object );
1280
- }
1281
- }
1282
- }
1283
-
1284
- /**
1285
- * Inspects to see if any mutable container owned by this object has been mutated, and treats any
1286
- * mutation as a new {@link #put(String, Object)} call.
1287
- */
1288
- /* package */ void checkForChangesToMutableContainers () {
1289
- synchronized (mutex ) {
1290
- for (String key : estimatedData .keySet ()) {
1291
- checkForChangesToMutableContainer (key , estimatedData .get (key ));
1292
- }
1293
- hashedObjects .keySet ().retainAll (estimatedData .values ());
1294
- }
1295
- }
1296
-
1297
- //endregion
1298
-
1299
1206
/**
1300
1207
* Accessor to the object id. An object id is assigned as soon as an object is saved to the
1301
1208
* server. The combination of a className and an objectId uniquely identifies an object in your
@@ -2983,8 +2890,6 @@ private void rebuildEstimatedData() {
2983
2890
ParseFieldOperation oldOperation = currentOperations ().get (key );
2984
2891
ParseFieldOperation newOperation = operation .mergeWithPrevious (oldOperation );
2985
2892
currentOperations ().put (key , newOperation );
2986
-
2987
- checkpointMutableContainer (key , newValue );
2988
2893
}
2989
2894
}
2990
2895
@@ -3512,7 +3417,6 @@ private ParseACL getACL(boolean mayCopy) {
3512
3417
if (mayCopy && ((ParseACL ) acl ).isShared ()) {
3513
3418
ParseACL copy = ((ParseACL ) acl ).copy ();
3514
3419
estimatedData .put (KEY_ACL , copy );
3515
- addToHashedObjects (copy );
3516
3420
return copy ;
3517
3421
}
3518
3422
return (ParseACL ) acl ;
0 commit comments