From a771283dd074acf4f79f7cd0fab7496a6ea3bd97 Mon Sep 17 00:00:00 2001 From: flexih Date: Fri, 15 Jun 2018 18:54:56 +0800 Subject: [PATCH] remove inline of _MASBoxValue to eliminate duplicate code size caused by inline function, which is 1.04KB(arm64) for most includes call. --- Masonry.xcodeproj/project.pbxproj | 6 +++ Masonry/MASUtilities.h | 60 +-------------------------- Masonry/MASUtilities.m | 69 +++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+), 59 deletions(-) create mode 100644 Masonry/MASUtilities.m diff --git a/Masonry.xcodeproj/project.pbxproj b/Masonry.xcodeproj/project.pbxproj index 1d7d2dab..f70fce65 100644 --- a/Masonry.xcodeproj/project.pbxproj +++ b/Masonry.xcodeproj/project.pbxproj @@ -57,6 +57,8 @@ 4473548E1B39F772004DACCB /* ViewController+MASAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 4473548C1B39F772004DACCB /* ViewController+MASAdditions.m */; }; 447354921B3A18B3004DACCB /* ViewController+MASAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 4473548C1B39F772004DACCB /* ViewController+MASAdditions.m */; }; 447354931B3A18B9004DACCB /* ViewController+MASAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 4473548B1B39F772004DACCB /* ViewController+MASAdditions.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 71B3A3F320D3D08800233591 /* MASUtilities.m in Sources */ = {isa = PBXBuildFile; fileRef = 71B3A3F220D3D08800233591 /* MASUtilities.m */; }; + 71B3A3F420D3D08800233591 /* MASUtilities.m in Sources */ = {isa = PBXBuildFile; fileRef = 71B3A3F220D3D08800233591 /* MASUtilities.m */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -88,6 +90,7 @@ 3AED06271AD5A1400053CC65 /* Masonry.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Masonry.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 4473548B1B39F772004DACCB /* ViewController+MASAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "ViewController+MASAdditions.h"; sourceTree = ""; }; 4473548C1B39F772004DACCB /* ViewController+MASAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "ViewController+MASAdditions.m"; sourceTree = ""; }; + 71B3A3F220D3D08800233591 /* MASUtilities.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASUtilities.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -130,6 +133,7 @@ children = ( 3AED05BC1AD59FD40053CC65 /* Masonry.h */, 3AED05E51AD5A0470053CC65 /* MASUtilities.h */, + 71B3A3F220D3D08800233591 /* MASUtilities.m */, 3AED05EF1AD5A0470053CC65 /* View+MASAdditions.h */, 3AED05F01AD5A0470053CC65 /* View+MASAdditions.m */, 3AED05F11AD5A0470053CC65 /* View+MASShorthandAdditions.h */, @@ -306,6 +310,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 71B3A3F320D3D08800233591 /* MASUtilities.m in Sources */, 3AED06011AD5A0470053CC65 /* NSArray+MASAdditions.m in Sources */, 3AED05FD1AD5A0470053CC65 /* MASViewAttribute.m in Sources */, 4473548E1B39F772004DACCB /* ViewController+MASAdditions.m in Sources */, @@ -323,6 +328,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 71B3A3F420D3D08800233591 /* MASUtilities.m in Sources */, 3AED060A1AD5A1400053CC65 /* NSArray+MASAdditions.m in Sources */, 3AED060B1AD5A1400053CC65 /* MASViewAttribute.m in Sources */, 3AED060C1AD5A1400053CC65 /* MASLayoutConstraint.m in Sources */, diff --git a/Masonry/MASUtilities.h b/Masonry/MASUtilities.h index 1dbfd938..2bae6a92 100644 --- a/Masonry/MASUtilities.h +++ b/Masonry/MASUtilities.h @@ -73,64 +73,6 @@ * Given a scalar or struct value, wraps it in NSValue * Based on EXPObjectify: https://github.com/specta/expecta */ -static inline id _MASBoxValue(const char *type, ...) { - va_list v; - va_start(v, type); - id obj = nil; - if (strcmp(type, @encode(id)) == 0) { - id actual = va_arg(v, id); - obj = actual; - } else if (strcmp(type, @encode(CGPoint)) == 0) { - CGPoint actual = (CGPoint)va_arg(v, CGPoint); - obj = [NSValue value:&actual withObjCType:type]; - } else if (strcmp(type, @encode(CGSize)) == 0) { - CGSize actual = (CGSize)va_arg(v, CGSize); - obj = [NSValue value:&actual withObjCType:type]; - } else if (strcmp(type, @encode(MASEdgeInsets)) == 0) { - MASEdgeInsets actual = (MASEdgeInsets)va_arg(v, MASEdgeInsets); - obj = [NSValue value:&actual withObjCType:type]; - } else if (strcmp(type, @encode(double)) == 0) { - double actual = (double)va_arg(v, double); - obj = [NSNumber numberWithDouble:actual]; - } else if (strcmp(type, @encode(float)) == 0) { - float actual = (float)va_arg(v, double); - obj = [NSNumber numberWithFloat:actual]; - } else if (strcmp(type, @encode(int)) == 0) { - int actual = (int)va_arg(v, int); - obj = [NSNumber numberWithInt:actual]; - } else if (strcmp(type, @encode(long)) == 0) { - long actual = (long)va_arg(v, long); - obj = [NSNumber numberWithLong:actual]; - } else if (strcmp(type, @encode(long long)) == 0) { - long long actual = (long long)va_arg(v, long long); - obj = [NSNumber numberWithLongLong:actual]; - } else if (strcmp(type, @encode(short)) == 0) { - short actual = (short)va_arg(v, int); - obj = [NSNumber numberWithShort:actual]; - } else if (strcmp(type, @encode(char)) == 0) { - char actual = (char)va_arg(v, int); - obj = [NSNumber numberWithChar:actual]; - } else if (strcmp(type, @encode(bool)) == 0) { - bool actual = (bool)va_arg(v, int); - obj = [NSNumber numberWithBool:actual]; - } else if (strcmp(type, @encode(unsigned char)) == 0) { - unsigned char actual = (unsigned char)va_arg(v, unsigned int); - obj = [NSNumber numberWithUnsignedChar:actual]; - } else if (strcmp(type, @encode(unsigned int)) == 0) { - unsigned int actual = (unsigned int)va_arg(v, unsigned int); - obj = [NSNumber numberWithUnsignedInt:actual]; - } else if (strcmp(type, @encode(unsigned long)) == 0) { - unsigned long actual = (unsigned long)va_arg(v, unsigned long); - obj = [NSNumber numberWithUnsignedLong:actual]; - } else if (strcmp(type, @encode(unsigned long long)) == 0) { - unsigned long long actual = (unsigned long long)va_arg(v, unsigned long long); - obj = [NSNumber numberWithUnsignedLongLong:actual]; - } else if (strcmp(type, @encode(unsigned short)) == 0) { - unsigned short actual = (unsigned short)va_arg(v, unsigned int); - obj = [NSNumber numberWithUnsignedShort:actual]; - } - va_end(v); - return obj; -} +id _MASBoxValue(const char *type, ...); #define MASBoxValue(value) _MASBoxValue(@encode(__typeof__((value))), (value)) diff --git a/Masonry/MASUtilities.m b/Masonry/MASUtilities.m new file mode 100644 index 00000000..4d8f9077 --- /dev/null +++ b/Masonry/MASUtilities.m @@ -0,0 +1,69 @@ +// +// MASUtilities.h +// Masonry +// +// Created by flexih on 15/06/18. +// Copyright (c) 2013 Jonas Budelmann. All rights reserved. +// + +#import "MASUtilities.h" + +id _MASBoxValue(const char *type, ...) { + va_list v; + va_start(v, type); + id obj = nil; + if (strcmp(type, @encode(id)) == 0) { + id actual = va_arg(v, id); + obj = actual; + } else if (strcmp(type, @encode(CGPoint)) == 0) { + CGPoint actual = (CGPoint)va_arg(v, CGPoint); + obj = [NSValue value:&actual withObjCType:type]; + } else if (strcmp(type, @encode(CGSize)) == 0) { + CGSize actual = (CGSize)va_arg(v, CGSize); + obj = [NSValue value:&actual withObjCType:type]; + } else if (strcmp(type, @encode(MASEdgeInsets)) == 0) { + MASEdgeInsets actual = (MASEdgeInsets)va_arg(v, MASEdgeInsets); + obj = [NSValue value:&actual withObjCType:type]; + } else if (strcmp(type, @encode(double)) == 0) { + double actual = (double)va_arg(v, double); + obj = [NSNumber numberWithDouble:actual]; + } else if (strcmp(type, @encode(float)) == 0) { + float actual = (float)va_arg(v, double); + obj = [NSNumber numberWithFloat:actual]; + } else if (strcmp(type, @encode(int)) == 0) { + int actual = (int)va_arg(v, int); + obj = [NSNumber numberWithInt:actual]; + } else if (strcmp(type, @encode(long)) == 0) { + long actual = (long)va_arg(v, long); + obj = [NSNumber numberWithLong:actual]; + } else if (strcmp(type, @encode(long long)) == 0) { + long long actual = (long long)va_arg(v, long long); + obj = [NSNumber numberWithLongLong:actual]; + } else if (strcmp(type, @encode(short)) == 0) { + short actual = (short)va_arg(v, int); + obj = [NSNumber numberWithShort:actual]; + } else if (strcmp(type, @encode(char)) == 0) { + char actual = (char)va_arg(v, int); + obj = [NSNumber numberWithChar:actual]; + } else if (strcmp(type, @encode(bool)) == 0) { + bool actual = (bool)va_arg(v, int); + obj = [NSNumber numberWithBool:actual]; + } else if (strcmp(type, @encode(unsigned char)) == 0) { + unsigned char actual = (unsigned char)va_arg(v, unsigned int); + obj = [NSNumber numberWithUnsignedChar:actual]; + } else if (strcmp(type, @encode(unsigned int)) == 0) { + unsigned int actual = (unsigned int)va_arg(v, unsigned int); + obj = [NSNumber numberWithUnsignedInt:actual]; + } else if (strcmp(type, @encode(unsigned long)) == 0) { + unsigned long actual = (unsigned long)va_arg(v, unsigned long); + obj = [NSNumber numberWithUnsignedLong:actual]; + } else if (strcmp(type, @encode(unsigned long long)) == 0) { + unsigned long long actual = (unsigned long long)va_arg(v, unsigned long long); + obj = [NSNumber numberWithUnsignedLongLong:actual]; + } else if (strcmp(type, @encode(unsigned short)) == 0) { + unsigned short actual = (unsigned short)va_arg(v, unsigned int); + obj = [NSNumber numberWithUnsignedShort:actual]; + } + va_end(v); + return obj; +}