Codemod: Clang-format for all files in ReactCommon directory

Summary:
We are moving towards 100%-prettified files. That's the first step when we apply Clang Format for `ReactCommon`.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D20110895

fbshipit-source-id: 0a0ce4997cf1c3721b0b07ef78c1a57ce87d20f9
This commit is contained in:
Valentin Shergin
2020-02-25 19:52:27 -08:00
committed by Facebook Github Bot
parent a3ade9e167
commit ede2c5031f
54 changed files with 895 additions and 696 deletions
+36 -20
View File
@@ -30,19 +30,22 @@ std::string normalizeName(std::string name) {
return name;
}
}
} // namespace
ModuleRegistry::ModuleRegistry(std::vector<std::unique_ptr<NativeModule>> modules, ModuleNotFoundCallback callback)
ModuleRegistry::ModuleRegistry(
std::vector<std::unique_ptr<NativeModule>> modules,
ModuleNotFoundCallback callback)
: modules_{std::move(modules)}, moduleNotFoundCallback_{callback} {}
void ModuleRegistry::updateModuleNamesFromIndex(size_t index) {
for (; index < modules_.size(); index++ ) {
for (; index < modules_.size(); index++) {
std::string name = normalizeName(modules_[index]->getName());
modulesByName_[name] = index;
}
}
void ModuleRegistry::registerModules(std::vector<std::unique_ptr<NativeModule>> modules) {
void ModuleRegistry::registerModules(
std::vector<std::unique_ptr<NativeModule>> modules) {
SystraceSection s_("ModuleRegistry::registerModules");
if (modules_.empty() && unknownModules_.empty()) {
modules_ = std::move(modules);
@@ -53,12 +56,15 @@ void ModuleRegistry::registerModules(std::vector<std::unique_ptr<NativeModule>>
modules_.reserve(modulesSize + addModulesSize);
std::move(modules.begin(), modules.end(), std::back_inserter(modules_));
if (!unknownModules_.empty()) {
for (size_t index = modulesSize; index < modulesSize + addModulesSize; index++) {
for (size_t index = modulesSize; index < modulesSize + addModulesSize;
index++) {
std::string name = normalizeName(modules_[index]->getName());
auto it = unknownModules_.find(name);
if (it != unknownModules_.end()) {
throw std::runtime_error(
folly::to<std::string>("module ", name, " was required without being registered and is now being registered."));
throw std::runtime_error(folly::to<std::string>(
"module ",
name,
" was required without being registered and is now being registered."));
} else if (addToNames) {
modulesByName_[name] = index;
}
@@ -80,7 +86,8 @@ std::vector<std::string> ModuleRegistry::moduleNames() {
return names;
}
folly::Optional<ModuleConfig> ModuleRegistry::getConfig(const std::string& name) {
folly::Optional<ModuleConfig> ModuleRegistry::getConfig(
const std::string &name) {
SystraceSection s("ModuleRegistry::getConfig", "module", name);
// Initialize modulesByName_
@@ -94,8 +101,7 @@ folly::Optional<ModuleConfig> ModuleRegistry::getConfig(const std::string& name)
if (unknownModules_.find(name) != unknownModules_.end()) {
return folly::none;
}
if (!moduleNotFoundCallback_ ||
!moduleNotFoundCallback_(name) ||
if (!moduleNotFoundCallback_ || !moduleNotFoundCallback_(name) ||
(it = modulesByName_.find(name)) == modulesByName_.end()) {
unknownModules_.insert(name);
return folly::none;
@@ -106,7 +112,8 @@ folly::Optional<ModuleConfig> ModuleRegistry::getConfig(const std::string& name)
CHECK(index < modules_.size());
NativeModule *module = modules_[index].get();
// string name, object constants, array methodNames (methodId is index), [array promiseMethodIds], [array syncMethodIds]
// string name, object constants, array methodNames (methodId is index),
// [array promiseMethodIds], [array syncMethodIds]
folly::dynamic config = folly::dynamic::array(name);
{
@@ -122,7 +129,7 @@ folly::Optional<ModuleConfig> ModuleRegistry::getConfig(const std::string& name)
folly::dynamic promiseMethodIds = folly::dynamic::array;
folly::dynamic syncMethodIds = folly::dynamic::array;
for (auto& descriptor : methods) {
for (auto &descriptor : methods) {
// TODO: #10487027 compare tags instead of doing string comparison?
methodNames.push_back(std::move(descriptor.name));
if (descriptor.type == "promise") {
@@ -151,20 +158,29 @@ folly::Optional<ModuleConfig> ModuleRegistry::getConfig(const std::string& name)
}
}
void ModuleRegistry::callNativeMethod(unsigned int moduleId, unsigned int methodId, folly::dynamic&& params, int callId) {
void ModuleRegistry::callNativeMethod(
unsigned int moduleId,
unsigned int methodId,
folly::dynamic &&params,
int callId) {
if (moduleId >= modules_.size()) {
throw std::runtime_error(
folly::to<std::string>("moduleId ", moduleId, " out of range [0..", modules_.size(), ")"));
throw std::runtime_error(folly::to<std::string>(
"moduleId ", moduleId, " out of range [0..", modules_.size(), ")"));
}
modules_[moduleId]->invoke(methodId, std::move(params), callId);
}
MethodCallResult ModuleRegistry::callSerializableNativeHook(unsigned int moduleId, unsigned int methodId, folly::dynamic&& params) {
MethodCallResult ModuleRegistry::callSerializableNativeHook(
unsigned int moduleId,
unsigned int methodId,
folly::dynamic &&params) {
if (moduleId >= modules_.size()) {
throw std::runtime_error(
folly::to<std::string>("moduleId ", moduleId, "out of range [0..", modules_.size(), ")"));
throw std::runtime_error(folly::to<std::string>(
"moduleId ", moduleId, "out of range [0..", modules_.size(), ")"));
}
return modules_[moduleId]->callSerializableNativeHook(methodId, std::move(params));
return modules_[moduleId]->callSerializableNativeHook(
methodId, std::move(params));
}
}}
} // namespace react
} // namespace facebook