Skip to content

Commit

Permalink
Remove RLMAccessorCode and objcType from RLMProperty
Browse files Browse the repository at this point in the history
There was a bunch of code related to tracking the exact declared type of
properties in RLMProperty, but the only thing this was actually used for was
generating the accessor method overrides for int properties, and that code can
easily just read the required size itself.

Similarly, RLMAccessorCode was no longer used for much of anything.
  • Loading branch information
tgoyne committed Feb 17, 2017
1 parent 559ef7d commit 844ef42
Show file tree
Hide file tree
Showing 8 changed files with 438 additions and 520 deletions.
399 changes: 165 additions & 234 deletions Realm/RLMAccessor.mm

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Realm/RLMObjectStore.mm
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ static NSUInteger createRowForObjectWithPrimaryKey(RLMClassInfo const& info, id
row.set_null(primaryColumnIndex); // FIXME: Use `set_null_unique` once Core supports it
}
break;

default:
REALM_UNREACHABLE();
}
Expand Down Expand Up @@ -269,7 +269,7 @@ static NSUInteger createOrGetRowForObject(RLMClassInfo const& info, F valueForPr
}

void RLMAddObjectToRealm(__unsafe_unretained RLMObjectBase *const object,
__unsafe_unretained RLMRealm *const realm,
__unsafe_unretained RLMRealm *const realm,
bool createOrUpdate) {
RLMVerifyInWriteTransaction(realm);

Expand Down
315 changes: 138 additions & 177 deletions Realm/RLMProperty.mm

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions Realm/RLMProperty_Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ FOUNDATION_EXTERN void RLMValidateSwiftPropertyName(NSString *name);

// private properties
@property (nonatomic, assign) NSUInteger index;
@property (nonatomic, assign) char objcType;
@property (nonatomic, copy) NSString *objcRawType;
@property (nonatomic, assign) BOOL isPrimary;
@property (nonatomic, assign) Ivar swiftIvar;

Expand Down
49 changes: 19 additions & 30 deletions Realm/Tests/MigrationTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -479,26 +479,14 @@ - (void)testChangingPropertyTypesRequiresMigration {
RLMObjectSchema *from = [RLMObjectSchema schemaForObjectClass:MigrationObject.class];

RLMObjectSchema *to = [RLMObjectSchema schemaForObjectClass:MigrationObject.class];
to.objectClass = RLMObject.class;
RLMProperty *prop = to.properties[0];
RLMProperty *strProp = to.properties[1];
prop.type = strProp.type;
prop.objcRawType = strProp.objcRawType;
prop.objcType = strProp.objcType;

[self assertMigrationRequiredForChangeFrom:@[from] to:@[to]];
}

- (void)testChangingIntSizeDoesNotRequireMigration {
RLMObjectSchema *from = [RLMObjectSchema schemaForObjectClass:MigrationObject.class];

RLMObjectSchema *to = [RLMObjectSchema schemaForObjectClass:MigrationObject.class];
RLMProperty *prop = to.properties[0];
prop.objcRawType = @"q"; // 'long long' rather than 'int'
prop.objcType = 'q';

[self assertNoMigrationRequiredForChangeFrom:@[from] to:@[to]];
}

- (void)testDeleteRealmIfMigrationNeededWithSetCustomSchema {
RLMObjectSchema *from = [RLMObjectSchema schemaForObjectClass:MigrationTwoStringObject.class];
from.properties = [from.properties subarrayWithRange:{0, 1}];
Expand Down Expand Up @@ -535,9 +523,9 @@ - (void)testDeleteRealmIfMigrationNeeded {
}

// Change string to int, requiring a migration
objectSchema.objectClass = RLMObject.class;
RLMProperty *stringCol = objectSchema.properties[1];
stringCol.type = RLMPropertyTypeInt;
stringCol.objcType = 'i';
stringCol.optional = NO;
objectSchema.properties = @[stringCol];

Expand Down Expand Up @@ -814,9 +802,9 @@ - (void)testRemoveAndAddProperty {
- (void)testChangePropertyType {
// make string an int
RLMObjectSchema *objectSchema = [RLMObjectSchema schemaForObjectClass:MigrationObject.class];
objectSchema.objectClass = RLMObject.class;
RLMProperty *stringCol = objectSchema.properties[1];
stringCol.type = RLMPropertyTypeInt;
stringCol.objcType = 'i';
stringCol.optional = NO;

// create realm with old schema and populate
Expand All @@ -829,7 +817,7 @@ - (void)testChangePropertyType {
RLMRealm *realm = [self migrateTestRealmWithBlock:^(RLMMigration *migration, uint64_t oldSchemaVersion) {
XCTAssertEqual(oldSchemaVersion, 0U, @"Initial schema version should be 0");
[migration enumerateObjects:MigrationObject.className
block:^(RLMObject *oldObject, RLMObject *newObject) {
block:^(RLMObject *oldObject, RLMObject *newObject) {
XCTAssertEqualObjects(newObject[@"intCol"], oldObject[@"intCol"]);
NSNumber *intObj = oldObject[@"stringCol"];
XCTAssert([intObj isKindOfClass:NSNumber.class], @"Old stringCol should be int");
Expand Down Expand Up @@ -1050,6 +1038,7 @@ - (void)testNullableToRequiredMigration {
[NSDate dateWithTimeIntervalSince1970:2]]];
}];

objectSchema.objectClass = RLMObject.class;
[objectSchema.properties setValue:@NO forKey:@"optional"];

RLMRealm *realm;
Expand All @@ -1068,22 +1057,22 @@ - (void)testNullableToRequiredMigration {
XCTAssertEqual(2U, allObjects.count);

AllOptionalTypes *obj = allObjects[0];
XCTAssertEqualObjects(@0, obj.intObj);
XCTAssertEqualObjects(@0, obj.floatObj);
XCTAssertEqualObjects(@0, obj.doubleObj);
XCTAssertEqualObjects(@0, obj.boolObj);
XCTAssertEqualObjects(@"", obj.string);
XCTAssertEqualObjects(NSData.data, obj.data);
XCTAssertEqualObjects([NSDate dateWithTimeIntervalSince1970:0], obj.date);
XCTAssertEqualObjects(@0, obj[@"intObj"]);
XCTAssertEqualObjects(@0, obj[@"floatObj"]);
XCTAssertEqualObjects(@0, obj[@"doubleObj"]);
XCTAssertEqualObjects(@0, obj[@"boolObj"]);
XCTAssertEqualObjects(@"", obj[@"string"]);
XCTAssertEqualObjects(NSData.data, obj[@"data"]);
XCTAssertEqualObjects([NSDate dateWithTimeIntervalSince1970:0], obj[@"date"]);

obj = allObjects[1];
XCTAssertEqualObjects(@0, obj.intObj);
XCTAssertEqualObjects(@0, obj.floatObj);
XCTAssertEqualObjects(@0, obj.doubleObj);
XCTAssertEqualObjects(@0, obj.boolObj);
XCTAssertEqualObjects(@"", obj.string);
XCTAssertEqualObjects(NSData.data, obj.data);
XCTAssertEqualObjects([NSDate dateWithTimeIntervalSince1970:0], obj.date);
XCTAssertEqualObjects(@0, obj[@"intObj"]);
XCTAssertEqualObjects(@0, obj[@"floatObj"]);
XCTAssertEqualObjects(@0, obj[@"doubleObj"]);
XCTAssertEqualObjects(@0, obj[@"boolObj"]);
XCTAssertEqualObjects(@"", obj[@"string"]);
XCTAssertEqualObjects(NSData.data, obj[@"data"]);
XCTAssertEqualObjects([NSDate dateWithTimeIntervalSince1970:0], obj[@"date"]);
}

- (void)testMigrationAfterReorderingProperties {
Expand Down
Loading

0 comments on commit 844ef42

Please sign in to comment.