From db373ea442ed41c398465075190a41f734f8dfa5 Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 5 Feb 2026 15:58:22 -0500 Subject: [PATCH] Use an IdentitySet when testing for elements added/removed from large persisted collections. --- ReStore/SSWDBOwnedCollectionSpec.cls | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/ReStore/SSWDBOwnedCollectionSpec.cls b/ReStore/SSWDBOwnedCollectionSpec.cls index a9497a5..a95e134 100644 --- a/ReStore/SSWDBOwnedCollectionSpec.cls +++ b/ReStore/SSWDBOwnedCollectionSpec.cls @@ -47,12 +47,21 @@ deleteQuery yourself! elementsIn: aCollection notIn: anotherCollection - - ^aCollection reject: [ :each | anotherCollection identityIncludes: each]! + | testAgainst | + "For small collections, the IdentitySet is actually slower, so just stick with the original collection in that common case." + testAgainst := anotherCollection size < 10 + ifTrue: [anotherCollection] + ifFalse: [anotherCollection asIdentitySet]. + ^aCollection reject: [:each | testAgainst identityIncludes: each].! hasCollection: updatedCollection anyAdditionsOrRemovalsFrom: originalCollection - - ^updatedCollection size ~= originalCollection size or: [updatedCollection anySatisfy: [ :each | (originalCollection identityIncludes: each) not]]! + | testAgainst | + updatedCollection size = originalCollection size ifFalse: [^true]. + "For small collections, the IdentitySet is actually slower, so just stick with the original collection in that common case." + testAgainst := originalCollection size < 10 + ifTrue: [originalCollection] + ifFalse: [originalCollection asIdentitySet]. + ^updatedCollection anySatisfy: [:each | (testAgainst identityIncludes: each) not].! orderingSpecs