Skip to content

Commit ecc8f81

Browse files
committed
fixes
1 parent b6158d3 commit ecc8f81

1 file changed

Lines changed: 10 additions & 18 deletions

File tree

packages/core/ios/RNSentryHexFormatter.h

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,30 @@
11
#import <Foundation/Foundation.h>
22

3-
// 2 for the "0x" prefix, plus 16 for the hex value, plus 1 for the null terminator.
3+
// 2 for the 0x prefix, plus 16 for the hex value, plus 1 for the null terminator
44
#define RN_SENTRY_HEX_ADDRESS_LENGTH 19
55

6-
/**
7-
* Formats a 64-bit unsigned integer as a zero-padded hex address string
8-
* (e.g. @c 0x000000010f1a2b3c).
9-
*
10-
* Inlined here so we don't need to reach into sentry-cocoa's private
11-
* @c SentryFormatter.h via @c HEADER_SEARCH_PATHS. Keep behavior identical
12-
* to @c sentry_snprintfHexAddress in sentry-cocoa.
13-
*/
146
static inline NSString *
157
rnsentry_snprintfHexAddress(uint64_t value)
168
{
179
char buffer[RN_SENTRY_HEX_ADDRESS_LENGTH];
1810
snprintf(buffer, RN_SENTRY_HEX_ADDRESS_LENGTH, "0x%016llx", value);
19-
return [NSString stringWithCString:buffer encoding:NSASCIIStringEncoding];
11+
NSString *nsString = [NSString stringWithCString:buffer encoding:NSASCIIStringEncoding];
12+
return nsString;
2013
}
2114

22-
/**
23-
* Formats an @c NSNumber address as a zero-padded hex string.
24-
* Drop-in replacement for sentry-cocoa's @c sentry_formatHexAddress.
25-
*/
2615
static inline NSString *
2716
rnsentry_formatHexAddress(NSNumber *value)
2817
{
18+
/*
19+
* We observed a 41% speedup by using snprintf vs +[NSString stringWithFormat:]. In a trial
20+
* using a profile, we observed the +[NSString stringWithFormat:] using 282ms of CPU time, vs
21+
* 164ms of CPU time for snprintf. There is also an assumed space improvement due to not needing
22+
* to allocate as many instances of NSString, like for the format string literal, instead only
23+
* using stack-bound C strings.
24+
*/
2925
return rnsentry_snprintfHexAddress([value unsignedLongLongValue]);
3026
}
3127

32-
/**
33-
* Formats a @c uint64_t address as a zero-padded hex string.
34-
* Drop-in replacement for sentry-cocoa's @c sentry_formatHexAddressUInt64.
35-
*/
3628
static inline NSString *
3729
rnsentry_formatHexAddressUInt64(uint64_t value)
3830
{

0 commit comments

Comments
 (0)