@@ -98,7 +98,9 @@ typedef NS_ENUM(uint32_t, FCType)
9898 FCTypeRect,
9999 FCTypeRange,
100100 FCTypeAffineTransform,
101- FCType3DTransform
101+ FCType3DTransform,
102+ FCTypeMutableIndexSet,
103+ FCTypeIndexSet,
102104};
103105
104106
@@ -601,6 +603,23 @@ static id FCRead3DTransform(NSUInteger *offset, const void *input, NSUInteger to
601603 return value;
602604}
603605
606+ static id FCReadMutableIndexSet (NSUInteger *offset, const void *input, NSUInteger total, __unsafe_unretained id cache)
607+ {
608+ uint32_t rangeCount = FCReadUInt32 (offset, input, total);
609+ __autoreleasing NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet ];
610+ FCCacheReadObject (indexSet, cache);
611+ for (uint32_t i=0 ; i<rangeCount; i++) {
612+ NSRange range = {FCReadUInt32 (offset, input, total), FCReadUInt32 (offset, input, total)};
613+ [indexSet addIndexesInRange: range];
614+ }
615+ return indexSet;
616+ }
617+
618+ static id FCReadIndexSet (NSUInteger *offset, const void *input, NSUInteger total, __unsafe_unretained id cache)
619+ {
620+ return [FCReadMutableIndexSet (offset, input, total, cache) copy ];
621+ }
622+
604623static id FCReadObject (NSUInteger *offset, const void *input, NSUInteger total, __unsafe_unretained id cache)
605624{
606625 static id (*constructors[])(NSUInteger *, const void *, NSUInteger , id ) =
@@ -636,6 +655,8 @@ static id (*constructors[])(NSUInteger *, const void *, NSUInteger, id) =
636655 FCReadRange,
637656 FCReadAffineTransform,
638657 FCRead3DTransform,
658+ FCReadMutableIndexSet,
659+ FCReadIndexSet,
639660 };
640661
641662 FCType type = FCReadUInt32 (offset, input, total);
@@ -934,6 +955,31 @@ - (void)FC_writeToOutput:(__unsafe_unretained NSMutableData *)output rootObject:
934955@end
935956
936957
958+ @implementation NSIndexSet (FastCoding)
959+
960+ - (void )FC_writeToOutput : (__unsafe_unretained NSMutableData *)output rootObject : (__unused id )object cache : (__unsafe_unretained id )cache
961+ {
962+ BOOL mutable = ([self classForCoder ] == [NSMutableIndexSet class ]);
963+ if (mutable) FCCacheWrittenObject (self, cache);
964+
965+ NSUInteger __block rangeCount = 0 ; // I wish we could get this directly from NSSet...
966+ [self enumerateRangesUsingBlock: ^(NSRange range, BOOL *stop) {
967+ rangeCount += 1 ;
968+ }];
969+
970+ FCWriteUInt32 (FCTypeIndexSet, output);
971+ FCWriteUInt32 (rangeCount, output);
972+ [self enumerateRangesUsingBlock: ^(NSRange range, BOOL *stop) {
973+ FCWriteUInt32 (range.location , output);
974+ FCWriteUInt32 (range.length , output);
975+ }];
976+
977+ if (!mutable) FCCacheWrittenObject (self, cache);
978+ }
979+
980+ @end
981+
982+
937983@implementation NSNumber (FastCoding)
938984
939985- (void )FC_writeToOutput : (__unsafe_unretained NSMutableData *)output rootObject : (__unused id )root cache : (__unsafe_unretained id )cache
0 commit comments