diff --git a/CHANGELOG.md b/CHANGELOG.md index c126bb64d5..9e3a7756b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Improvements - Speed up HTTP tracking for multiple requests in parallel (#4366) +- Slightly speed up SentryInAppLogic (#4370) ## 8.37.0-beta.1 diff --git a/Sources/Sentry/SentryInAppLogic.m b/Sources/Sentry/SentryInAppLogic.m index 1b5ac288b2..4482120590 100644 --- a/Sources/Sentry/SentryInAppLogic.m +++ b/Sources/Sentry/SentryInAppLogic.m @@ -1,4 +1,5 @@ #import "SentryInAppLogic.h" +#import "SentryLog.h" #import #import @@ -10,8 +11,19 @@ - (instancetype)initWithInAppIncludes:(NSArray *)inAppIncludes inAppExcludes:(NSArray *)inAppExcludes { if (self = [super init]) { - _inAppIncludes = inAppIncludes; - _inAppExcludes = inAppExcludes; + NSMutableArray *includes = + [[NSMutableArray alloc] initWithCapacity:inAppIncludes.count]; + for (NSString *include in inAppIncludes) { + [includes addObject:include.lowercaseString]; + } + _inAppIncludes = includes; + + NSMutableArray *excludes = + [[NSMutableArray alloc] initWithCapacity:inAppExcludes.count]; + for (NSString *exclude in inAppExcludes) { + [excludes addObject:exclude.lowercaseString]; + } + _inAppExcludes = excludes; } return self; @@ -23,13 +35,17 @@ - (BOOL)isInApp:(nullable NSString *)imageName return NO; } + NSString *imageNameLastPathComponent = imageName.lastPathComponent.lowercaseString; + for (NSString *inAppInclude in self.inAppIncludes) { - if ([SentryInAppLogic isImageNameInApp:imageName inAppInclude:inAppInclude]) + if ([SentryInAppLogic isImageNameLastPathComponentInApp:imageNameLastPathComponent + inAppInclude:inAppInclude]) + return YES; } - for (NSString *inAppExlude in self.inAppExcludes) { - if ([imageName.lastPathComponent.lowercaseString hasPrefix:inAppExlude.lowercaseString]) + for (NSString *inAppExclude in self.inAppExcludes) { + if ([imageNameLastPathComponent hasPrefix:inAppExclude]) return NO; } @@ -48,7 +64,15 @@ - (BOOL)isClassInApp:(Class)targetClass + (BOOL)isImageNameInApp:(NSString *)imageName inAppInclude:(NSString *)inAppInclude { - return [imageName.lastPathComponent.lowercaseString hasPrefix:inAppInclude.lowercaseString]; + return [SentryInAppLogic + isImageNameLastPathComponentInApp:imageName.lastPathComponent.lowercaseString + inAppInclude:inAppInclude]; +} + ++ (BOOL)isImageNameLastPathComponentInApp:(NSString *)imageNameLastPathComponent + inAppInclude:(NSString *)inAppInclude +{ + return [imageNameLastPathComponent hasPrefix:inAppInclude]; } @end