Skip to content

Commit

Permalink
Merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
orta committed Jan 21, 2019
2 parents ddabecb + c72da46 commit b67463e
Show file tree
Hide file tree
Showing 517 changed files with 4,696 additions and 44,977 deletions.
30 changes: 30 additions & 0 deletions Local Podspecs/Mantle.podspec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "Mantle",
"version": "2.1.0",
"summary": "Model framework for Cocoa and Cocoa Touch.",
"homepage": "https://github.com/Mantle/Mantle",
"license": "MIT",
"authors": {
"Github": "[email protected]"
},
"source": {
"git": "https://github.com/github/Mantle.git",
"tag": "2.1.0"
},
"platforms": {
"ios": "5.0",
"osx": "10.7",
"watchos": "2.0",
"tvos": "9.0"
},
"requires_arc": true,
"frameworks": "Foundation",
"source_files": "Mantle",
"subspecs": [
{
"name": "extobjc",
"source_files": "Mantle/extobjc",
"private_header_files": "Mantle/extobjc/*.h"
}
]
}
2 changes: 1 addition & 1 deletion Manifest.lock
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,6 @@ SPEC CHECKSUMS:
YYImage: 1e1b62a9997399593e4b9c4ecfbbabbf1d3f3b54
ZXingObjC: 512b34b9b6920e8ef0461a4159d0814c5e48c28a

PODFILE CHECKSUM: 5c0b63b106dcb0f2f6dcce6f03ac8b9a62667426
PODFILE CHECKSUM: a149d95740501fcc17930af44af9e935d86bee70

COCOAPODS: 1.5.3
6 changes: 3 additions & 3 deletions Mantle/Mantle/MTLJSONAdapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,14 @@ extern NSString * const MTLJSONAdapterThrownExceptionErrorKey;
/// A value transformer that should be used for a properties of the given
/// primitive type.
///
/// If `objCType` matches @encode(id), the value transformer returned by
/// If `objCType` matches @encode(id), the value transformer returned by
/// +transformerForModelPropertiesOfClass: is used instead.
///
/// The default implementation transforms properties that match @encode(BOOL)
/// The default implementation transforms properties that match @encode(BOOL)
/// using the MTLBooleanValueTransformerName transformer.
///
/// objCType - The type encoding for the value of this property. This is the type
/// as it would be returned by the @encode() directive.
/// as it would be returned by the @encode() directive.
///
/// Returns a value transformer or nil if no transformation should be used.
+ (NSValueTransformer *)transformerForModelPropertiesOfObjCType:(const char *)objCType;
Expand Down
13 changes: 12 additions & 1 deletion Mantle/Mantle/MTLJSONAdapter.m
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,18 @@ - (id)modelFromJSONDictionary:(NSDictionary *)JSONDictionary error:(NSError **)e

id model = [self.modelClass modelWithDictionary:dictionaryValue error:error];

return [model validate:error] ? model : nil;
// BEGIN ORM-PERF-2
// Commented out by mkirk as part of ORM perf optimizations.
//
// The validation NSCoding validation reflection used by Mantle is expensive, and
// we've never used it.
// If we later want to use this feature, we'll need to carefully evaluate the perf
// implications on large migrations.
//
// return [model validate:error] ? model : nil;
//
return model;
// END ORM-PERF-2
}

+ (NSDictionary *)valueTransformersForModelClass:(Class)modelClass {
Expand Down
49 changes: 41 additions & 8 deletions Mantle/Mantle/MTLModel+NSCoding.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@
// Used to cache the reflection performed in +allowedSecureCodingClassesByPropertyKey.
static void *MTLModelCachedAllowedClassesKey = &MTLModelCachedAllowedClassesKey;

// BEGIN ORM-PERF-3
// Added by mkirk as part of ORM perf optimizations.
//
// +encodingBehaviorsByPropertyKey is somewhat expensive, so we follow existing library patterns
// to cache the computed reflection on the class via an associated object
// Used to cache the reflection performed in +encodingBehaviorsByPropertyKey.
static void *MTLModelCachedEncodingBehaviorsByPropertyKeyKey = &MTLModelCachedEncodingBehaviorsByPropertyKeyKey;
// END ORM-PERF-3

// Returns whether the given NSCoder requires secure coding.
static BOOL coderRequiresSecureCoding(NSCoder *coder) {
SEL requiresSecureCodingSelector = @selector(requiresSecureCoding);
Expand Down Expand Up @@ -63,6 +72,15 @@ + (NSUInteger)modelVersion {
#pragma mark Encoding Behaviors

+ (NSDictionary *)encodingBehaviorsByPropertyKey {
// BEGIN ORM-PERF-3
// Added by mkirk as part of ORM perf optimizations.
//
// +encodingBehaviorsByPropertyKey is somewhat expensive, so we follow existing library patterns
// to cache the computed reflection on the class via an associated object
NSDictionary *cachedBehaviors = objc_getAssociatedObject(self, MTLModelCachedEncodingBehaviorsByPropertyKeyKey);
if (cachedBehaviors != nil) return cachedBehaviors;
// END ORM-PERF-3

NSSet *propertyKeys = self.propertyKeys;
NSMutableDictionary *behaviors = [[NSMutableDictionary alloc] initWithCapacity:propertyKeys.count];

Expand All @@ -79,6 +97,14 @@ + (NSDictionary *)encodingBehaviorsByPropertyKey {
behaviors[key] = @(behavior);
}

// BEGIN ORM-PERF-3
// Added by mkirk as part of ORM perf optimizations.
//
// +encodingBehaviorsByPropertyKey is somewhat expensive, so we follow existing library patterns
// to cache the computed reflection on the class via an associated object
objc_setAssociatedObject(self, MTLModelCachedEncodingBehaviorsByPropertyKeyKey, behaviors, OBJC_ASSOCIATION_COPY);
// END ORM-PERF-3

return behaviors;
}

Expand Down Expand Up @@ -126,14 +152,21 @@ - (id)decodeValueForKey:(NSString *)key withCoder:(NSCoder *)coder modelVersion:
NSParameterAssert(key != nil);
NSParameterAssert(coder != nil);

SEL selector = MTLSelectorWithCapitalizedKeyPattern("decode", key, "WithCoder:modelVersion:");
if ([self respondsToSelector:selector]) {
IMP imp = [self methodForSelector:selector];
id (*function)(id, SEL, NSCoder *, NSUInteger) = (__typeof__(function))imp;
id result = function(self, selector, coder, modelVersion);

return result;
}
// BEGIN ORM-PERF-1
// Commented out by mkirk as part of ORM perf optimizations.
// The `MTLSelectorWithCapitalizedKeyPattern` can be quite expensive in aggregate
// and we're not using the reflective features that require it.
// If we later want to use this feature, we'll need to carefully evaluate the perf
// implications on large migrations.
// SEL selector = MTLSelectorWithCapitalizedKeyPattern("decode", key, "WithCoder:modelVersion:");
// if ([self respondsToSelector:selector]) {
// IMP imp = [self methodForSelector:selector];
// id (*function)(id, SEL, NSCoder *, NSUInteger) = (__typeof__(function))imp;
// id result = function(self, selector, coder, modelVersion);
//
// return result;
// }
// END ORM-PERF-1

@try {
if (coderRequiresSecureCoding(coder)) {
Expand Down
67 changes: 46 additions & 21 deletions Mantle/Mantle/MTLModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,16 @@ typedef enum : NSUInteger {
/// Returns an initialized model object, or nil if validation failed.
- (instancetype)initWithDictionary:(NSDictionary *)dictionaryValue error:(NSError **)error;

// BEGIN ORM-PERF-1
// Commented out by mkirk as part of ORM perf optimizations.
// The `MTLSelectorWithCapitalizedKeyPattern` can be quite expensive in aggregate
// and we're not using the reflective features that require it.
// If we later want to use this feature, we'll need to carefully evaluate the perf
// implications on large migrations.
/// Merges the value of the given key on the receiver with the value of the same
/// key from the given model object, giving precedence to the other model object.
- (void)mergeValueForKey:(NSString *)key fromModel:(id<MTLModel>)model;
//- (void)mergeValueForKey:(NSString *)key fromModel:(id<MTLModel>)model;
// END ORM-PERF-1

/// Returns the keys for all @property declarations, except for `readonly`
/// properties without ivars, or properties on MTLModel itself.
Expand All @@ -90,7 +97,7 @@ typedef enum : NSUInteger {
/// validation
///
/// Returns YES if the model is valid, or NO if the validation failed.
- (BOOL)validate:(NSError **)error;
//- (BOOL)validate:(NSError **)error;

@end

Expand Down Expand Up @@ -120,16 +127,24 @@ typedef enum : NSUInteger {
/// This is the designated initializer for this class.
- (instancetype)init;

// BEGIN ORM-PERF-1
// Commented out by mkirk as part of ORM perf optimizations.
// The `MTLSelectorWithCapitalizedKeyPattern` can be quite expensive in aggregate
// and we're not using the reflective features that require it.
// If we later want to use this feature, we'll need to carefully evaluate the perf
// implications on large migrations.
/// By default, this method looks for a `-merge<Key>FromModel:` method on the
/// receiver, and invokes it if found. If not found, and `model` is not nil, the
/// value for the given key is taken from `model`.
- (void)mergeValueForKey:(NSString *)key fromModel:(id<MTLModel>)model;

//- (void)mergeValueForKey:(NSString *)key fromModel:(id<MTLModel>)model;
//
/// Merges the values of the given model object into the receiver, using
/// -mergeValueForKey:fromModel: for each key in +propertyKeys.
///
/// `model` must be an instance of the receiver's class or a subclass thereof.
- (void)mergeValuesForKeysFromModel:(id<MTLModel>)model;
//- (void)mergeValuesForKeysFromModel:(id<MTLModel>)model;
//
// END ORM-PERF-1

/// The storage behavior of a given key.
///
Expand Down Expand Up @@ -161,19 +176,29 @@ typedef enum : NSUInteger {

@end

/// Implements validation logic for MTLModel.
@interface MTLModel (Validation)

/// Validates the model.
///
/// The default implementation simply invokes -validateValue:forKey:error: with
/// all +propertyKeys and their current value. If -validateValue:forKey:error:
/// returns a new value, the property is set to that new value.
///
/// error - If not NULL, this may be set to any error that occurs during
/// validation
///
/// Returns YES if the model is valid, or NO if the validation failed.
- (BOOL)validate:(NSError **)error;

@end
// BEGIN ORM-PERF-2
// Commented out by mkirk as part of ORM perf optimizations.
//
// The validation NSCoding validation reflection used by Mantle is expensive, and
// we've never used it.
// If we later want to use this feature, we'll need to carefully evaluate the perf
// implications on large migrations.
//
///// Implements validation logic for MTLModel.
//@interface MTLModel (Validation)
//
///// Validates the model.
/////
///// The default implementation simply invokes -validateValue:forKey:error: with
///// all +propertyKeys and their current value. If -validateValue:forKey:error:
///// returns a new value, the property is set to that new value.
/////
///// error - If not NULL, this may be set to any error that occurs during
///// validation
/////
///// Returns YES if the model is valid, or NO if the validation failed.
//- (BOOL)validate:(NSError **)error;
//
//@end
//
// END ORM-PERF-2
Loading

0 comments on commit b67463e

Please sign in to comment.