|
1 | 1 | #import <Foundation/Foundation.h> |
2 | 2 |
|
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 |
4 | 4 | #define RN_SENTRY_HEX_ADDRESS_LENGTH 19 |
5 | 5 |
|
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 | | - */ |
14 | 6 | static inline NSString * |
15 | 7 | rnsentry_snprintfHexAddress(uint64_t value) |
16 | 8 | { |
17 | 9 | char buffer[RN_SENTRY_HEX_ADDRESS_LENGTH]; |
18 | 10 | 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; |
20 | 13 | } |
21 | 14 |
|
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 | | - */ |
26 | 15 | static inline NSString * |
27 | 16 | rnsentry_formatHexAddress(NSNumber *value) |
28 | 17 | { |
| 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 | + */ |
29 | 25 | return rnsentry_snprintfHexAddress([value unsignedLongLongValue]); |
30 | 26 | } |
31 | 27 |
|
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 | | - */ |
36 | 28 | static inline NSString * |
37 | 29 | rnsentry_formatHexAddressUInt64(uint64_t value) |
38 | 30 | { |
|
0 commit comments