react-native-macos/ReactCommon
Samuel Susla 81a97de546 Prevent type conversion in Differentiator
Summary:
changelog: [internal]

Prevents 2 type converions:
1. int <-> size_t
2. int <-> int32_t

# Why is using size_t better when working with indexes.

## 1. Type conversion isn't for free.

Take this example

```
size_t calculate(int number) {
  return number + 1;
}
```

It generates following assembly (generated with armv8-a clang 10.0.0):

```
calculate(int):                          // calculate(int)
sub     sp, sp, #16                     // =16
str     w0, [sp, #12]
ldr     w8, [sp, #12]
add     w9, w8, #1                      // =1
mov     w8, w9
sxtw    x0, w8
add     sp, sp, #16                     // =16
ret
```

That's 9 instructions.

If we get rid of type conversion:

```
size_t calculate(size_t number) {
  return number + 1;
}
```

Assembly (generated with armv8-a clang 10.0.0):

```
calculate(unsigned long):                          // calculate(unsigned long)
sub     sp, sp, #16             // =16
str     x0, [sp, #8]
ldr     x8, [sp, #8]
add     x0, x8, #1              // =1
add     sp, sp, #16             // =16
ret
```

Compiler now produces only 7 instructions.

## Semantics

When using int for indexing, the type doesn't say much. By using `size_t`, just by looking at the type, it gives the reader more information about where it is coming from.

Reviewed By: JoshuaGross

Differential Revision: D24332248

fbshipit-source-id: 87ef982829ec14906ed9e002ea2e875fda4a0cd8
2020-10-15 15:15:41 -07:00
..
better Extend 'better' module to compile in OSS 2020-08-06 11:53:04 -07:00
callinvoker remove most of tvOS remnants from the code (#29407) 2020-09-28 21:26:41 -07:00
cxxreact Add ReactMarker::logTaggedMarkerWithInstanceKey 2020-10-01 14:16:32 -07:00
hermes Add HeapProfiler.lastSeenObjectId and HeapProfiler.heapStatsUpdate to inspector 2020-10-10 13:26:13 -07:00
jsengineinstance The life-changing magic of clang-tidying up 2020-02-04 11:09:30 -08:00
jsi Add HeapProfiler.lastSeenObjectId and HeapProfiler.heapStatsUpdate to inspector 2020-10-10 13:26:13 -07:00
jsiexecutor Change the memory warning forced GC to use the level name 2020-10-03 10:11:06 -07:00
jsinspector remove most of tvOS remnants from the code (#29407) 2020-09-28 21:26:41 -07:00
libraries/fbcore/src/test/java/com/facebook/powermock Fix RN OSS build (#29221) 2020-06-25 11:09:42 -07:00
microprofiler use xplat BUCK attribution 2020-05-15 21:55:52 -07:00
react Prevent type conversion in Differentiator 2020-10-15 15:15:41 -07:00
reactperflogger Log QPL Events from TM + NM, when Perf. Logging is enabled 2020-10-10 02:51:59 -07:00
runtimeexecutor remove most of tvOS remnants from the code (#29407) 2020-09-28 21:26:41 -07:00
yoga remove most of tvOS remnants from the code (#29407) 2020-09-28 21:26:41 -07:00
React-Fabric.podspec remove most of tvOS remnants from the code (#29407) 2020-09-28 21:26:41 -07:00
ReactCommon.podspec TurboModule Android: move SampleTurboModule impl and spec to OSS 2020-09-29 18:41:14 -07:00
common.mk More robust hermes-engine lookup logic in makefiles (#26820) 2019-10-14 19:21:43 -07:00