react-native-macos/ReactCommon
Samuel Susla 5fa6c5a941 Enable modernize-pass-by-value clang tidy rule
Summary:
changelog: [internal]

You can read more about this rule on https://clang.llvm.org/extra/clang-tidy/checks/modernize-pass-by-value.html

# Isn't it wasteful to copy? Isn't reference more efficient?

This rule of thumb is no longer true since C++11 with move semantics. Let's look at some examples.

# Option one

```
class TextHolder
{
public:
   TextBox(std::string const &text) : text_(text) {}
private:
   std::string text_;
};
```

By using reference here, we prevent the caller from using rvalue to and avoiding copy. Regardless of what the caller passes in, copy always happens.

# Option two

```
class TextHolder
{
public:
   TextBox(std::string const &text) : text_(text) {}
   TextBox(std::string &&text) : text_(std::move(text)) {}
private:
   std::string text_;
};
```
Here, we provide two constructors, one for const reference and one for rvalue reference. This gives the caller option to avoid copy. But now we have two constructors, which is not ideal.

# Option three (what we do in this diff)

```
class TextHolder
{
public:
   TextBox(std::string text) : text_(std::move(text)) {}
private:
   std::string text_;
};
```
Here, the caller has option to avoid copy and we only have single constructor.

Reviewed By: fkgozali, JoshuaGross

Differential Revision: D33276841

fbshipit-source-id: 619d5123d2e28937b22874650366629f24f20a63
2021-12-23 07:53:48 -08:00
..
butter Butter C++: clarify goals/intent in the comment 2021-12-20 23:38:52 -08:00
callinvoker Remove compiler_flags from BUCK modules 2021-10-14 15:34:29 -07:00
cxxreact Remove usages of bump-oss-version from generated scripts 2021-12-17 18:37:37 -08:00
hermes Static link for hermes-inspector (#32694) 2021-12-13 07:48:39 -08:00
jsengineinstance The life-changing magic of clang-tidying up 2020-02-04 11:09:30 -08:00
jsi jsi.h Fix typo 2021-11-16 08:56:53 -08:00
jsiexecutor Link RCT-Folly against libc++abi 2021-09-16 22:24:10 -07:00
jsinspector Fix JSInspector build error on windows (#32585) 2021-11-15 11:44:37 -08:00
libraries/fbcore/src/test/java/com/facebook/powermock Explicitly set autoglob (long tail) 2020-12-17 19:35:29 -08:00
logger Remove compiler_flags from BUCK modules 2021-10-14 15:34:29 -07:00
microprofiler use xplat BUCK attribution 2020-05-15 21:55:52 -07:00
react Enable modernize-pass-by-value clang tidy rule 2021-12-23 07:53:48 -08:00
reactperflogger Remove compiler_flags from BUCK modules 2021-10-14 15:34:29 -07:00
runtimeexecutor Update libruntimeexector to be a shared lib rather than a static lib 2021-11-24 10:58:54 -08:00
yoga Remove compiler_flags from BUCK modules 2021-10-14 15:34:29 -07:00
React-Fabric.podspec C++ - better => butter 2021-12-20 22:25:14 -08:00
React-rncore.podspec Fix a build issue where codegen order is incorrect (#32480) 2021-10-27 09:45:25 -07:00
ReactCommon.podspec Link RCT-Folly against libc++abi 2021-09-16 22:24:10 -07:00
common.mk More robust hermes-engine lookup logic in makefiles (#26820) 2019-10-14 19:21:43 -07:00