Skip to content
This repository was archived by the owner on Aug 14, 2019. It is now read-only.

Commit 5e9e368

Browse files
committed
Remove unneeded CGContext Save and Restore calls.
In the private class methods of JSQMessagesAvatarImageFactory (jsq_imageWitInitials, jsq_circularImage) there were calls to save and restore the state of the graphic context. The calls are not needed because UIGraphicsBeginImageContext creates a new context in a default state.
1 parent 4c05c28 commit 5e9e368

1 file changed

Lines changed: 1 addition & 5 deletions

File tree

JSQMessagesViewController/Factories/JSQMessagesAvatarImageFactory.m

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,13 @@ + (UIImage *)jsq_imageWitInitials:(NSString *)initials
130130
UIGraphicsBeginImageContextWithOptions(frame.size, NO, [UIScreen mainScreen].scale);
131131
{
132132
CGContextRef context = UIGraphicsGetCurrentContext();
133-
CGContextSaveGState(context);
134133

135134
CGContextSetFillColorWithColor(context, backgroundColor.CGColor);
136135
CGContextFillRect(context, frame);
137136
[initials drawAtPoint:drawPoint withAttributes:attributes];
138137

139138
image = UIGraphicsGetImageFromCurrentImageContext();
140139

141-
CGContextRestoreGState(context);
142140
}
143141
UIGraphicsEndImageContext();
144142

@@ -156,7 +154,6 @@ + (UIImage *)jsq_circularImage:(UIImage *)image withDiameter:(NSUInteger)diamete
156154
UIGraphicsBeginImageContextWithOptions(frame.size, NO, [UIScreen mainScreen].scale);
157155
{
158156
CGContextRef context = UIGraphicsGetCurrentContext();
159-
CGContextSaveGState(context);
160157

161158
UIBezierPath *imgPath = [UIBezierPath bezierPathWithOvalInRect:frame];
162159
[imgPath addClip];
@@ -168,8 +165,7 @@ + (UIImage *)jsq_circularImage:(UIImage *)image withDiameter:(NSUInteger)diamete
168165
}
169166

170167
newImage = UIGraphicsGetImageFromCurrentImageContext();
171-
172-
CGContextRestoreGState(context);
168+
173169
}
174170
UIGraphicsEndImageContext();
175171

0 commit comments

Comments
 (0)