Skip to content

Commit

Permalink
Unbroke SVGBezierPath file cache
Browse files Browse the repository at this point in the history
  • Loading branch information
fjolnir committed Jan 27, 2017
1 parent a9af80c commit b1353a1
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions SVGBezierPath.mm
Expand Up @@ -26,9 +26,9 @@ - (instancetype)init
}
#endif

+ (NSCache<NSString*, NSArray<SVGBezierPath*>*> *)_svg_pathCache
+ (NSCache<NSURL*, NSArray<SVGBezierPath*>*> *)_svg_pathCache
{
static NSCache<NSString*, NSArray<SVGBezierPath*>*> *pathCache;
static NSCache<NSURL*, NSArray<SVGBezierPath*>*> *pathCache;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
pathCache = [NSCache new];
Expand All @@ -42,13 +42,18 @@ + (void)resetCache

+ (NSArray<SVGBezierPath*> *)pathsFromSVGAtURL:(NSURL *)aURL
{
return [self pathsFromSVGString:[NSString stringWithContentsOfURL:aURL
usedEncoding:NULL
error:NULL]];
NSArray<SVGBezierPath*> *paths = [self.class._svg_pathCache objectForKey:aURL];
if (!paths) {
paths = [self pathsFromSVGString:[NSString stringWithContentsOfURL:aURL
usedEncoding:NULL
error:NULL]];
if (paths) {
[self.class._svg_pathCache setObject:paths forKey:aURL];
}
}
return [[NSArray alloc] initWithArray:paths copyItems:YES];
}



+ (NSArray *)pathsFromSVGString:(NSString * const)svgString
{
SVGAttributeSet *cgAttrs;
Expand Down

0 comments on commit b1353a1

Please sign in to comment.